數字我發現這個代碼來獲得一個字符串的所有單詞,查找所有單詞,而不使用正則表達式
static string[] GetWords(string input)
{
MatchCollection matches = Regex.Matches(input, @"\b[\w']*\b");
var words = from m in matches.Cast<Match>()
where !string.IsNullOrEmpty(m.Value)
select TrimSuffix(m.Value);
return words.ToArray();
}
static string TrimSuffix(string word)
{
int apostrapheLocation = word.IndexOf('\'');
if (apostrapheLocation != -1)
{
word = word.Substring(0, apostrapheLocation);
}
return word;
}
- 請介紹有關的代碼。
- 我怎樣才能不數字的話嗎?
英語糾錯:你大概的意思:請描述一下代碼的功能和/或它是如何工作的。 「描述」是不合語法的,過於模糊。 – 2011-04-22 11:43:37
@Robin Green謝謝,我是英語新手。 – Shahin 2011-04-22 11:47:46