這可能給你一些線索 - 沒有在附近真正的代碼質量,並且只有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