这可能给你一些线索 - 没有在附近真正的代码质量,并且只有5分钟的工作来与这种伪劣解决方案,但没有做什么你需要。它闻到很多被警告。
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
namespace test {
class Program {
static void Main(string[] args) {
String mainString="//BUY/SELL//ORDERTIME//RT//QTY//BROKERAGE//NETRATE//AMOUNTRS//RATE//SCNM//";
Hashtable ht = createHashTable(mainString);
if (hasValue("RA", ht)) {
Console.WriteLine("Matched RA");
} else {
Console.WriteLine("Didnt Find RA");
}
if (hasValue("RATE", ht)) {
Console.WriteLine("Matched RATE");
}
Console.Read();
}
public static Hashtable createHashTable(string strToSplit) {
Hashtable ht = new Hashtable();
int iCount = 0;
string[] words = strToSplit.Split(new Char[] { '/', '/', '/' });
foreach (string word in words) {
ht.Add(iCount++, word);
}
return ht;
}
public static bool hasValue(string strValuetoSearch, Hashtable ht) {
return ht.ContainsValue(strValuetoSearch);
}
}
}
来源
2010-04-08 11:04:40
jpg
*为什么*它应该匹配RT而不是ORDERTIME? *为什么*应该匹配RATE而不是NETRATE? – 2010-04-08 10:35:26
你是什么意思与“匹配”;你只是想检查字符串是否存在? – 2010-04-08 10:35:34
@Jon Skeet先生,因为我想知道在一个字符串中完成匹配的位置? – Harikrishna 2010-04-08 10:41:00