【发布时间】:2012-07-10 02:23:02
【问题描述】:
有没有比这更好的方法将 MatchCollection 转换为字符串数组?
MatchCollection mc = Regex.Matches(strText, @"\b[A-Za-z-']+\b");
string[] strArray = new string[mc.Count];
for (int i = 0; i < mc.Count;i++ )
{
strArray[i] = mc[i].Groups[0].Value;
}
P.S.:mc.CopyTo(strArray,0) 抛出异常:
源数组中的至少一个元素无法转换为目标数组类型。
【问题讨论】: