我正在循環一個數組,並再次循環這些值,以匹配它與字符串,如果整個給定的字符串匹配將數組的整個元素,他們我應該打印該字符串,但它不工作匹配一個字符串與數組
public class find
{
string[] inputs = {"Third Street Promenade, 1220 3rd St ,Santa Monica, CA 90401","Hi there should"};
string store_tran1 = "1220 3rd St ,Santa Monica, CA 90401"
foreach(var store in stores){
List<string> outputs = new List<string>();
foreach (var input in inputs)
{
outputs.AddRange((new String(input.ToCharArray()
.Where(c => Char.IsLetterOrDigit(c) || c == ' ')
.ToArray()).Split(' ')));
}
foreach (var output in outputs)
{
//string sto = store.ToString();
//Console.Write (output+"\n");
bool store_match_check_1 = Regex.IsMatch (store_tran1, @""+Regex.Escape (output)+"", RegexOptions.IgnoreCase);
if (store_match_check_1 == true) {
//string store_match_check1 = store_match_check_1.Groups [1].Value;
res = true;
} else {
store_array_check.Add ("one");
res = false;
}
}
}
}
預期輸出:
Third Street Promenade, 1220 3rd St ,Santa Monica, CA 9040
我怎麼能得到這個沃金
爲什麼在使用正則表達式時只能使用字符串Contains()方法? – jdweng
請修復您的縮進以使我們更輕鬆。 :) – nicomp