【发布时间】:2010-02-11 01:17:48
【问题描述】:
有没有比这个函数更快的方法来比较两个字符串(使用空格作为通配符)?
public static bool CustomCompare(this string word, string mask)
{
for (int index = 0; index < mask.Length; index++)
{
if (mask[index] != ' ') && (mask[index]!= word[index]))
{
return false;
}
}
return true;
}
示例:“S nt nce”与“Sentence”比较将返回 true。 (被比较的两个需要相同的长度)
【问题讨论】:
-
所以你不需要像文件系统 * 通配符这样的可变宽度通配符?
-
目前我不需要它,因为我总是用这个函数比较相同长度的字符串
标签: c# string comparison