有没有比这更好的方法将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;
}
Run Code Online (Sandbox Code Playgroud)
PS:mc.CopyTo(strArray,0)
抛出异常:
源数组中至少有一个元素无法转换为目标数组类型.
我有很多单词的清单.我需要的是找到以"ing","ed","ied"结尾的所有单词以及单个元音和加倍辅音之前:应该匹配单词:begged,slamming,zagging.不匹配帮助("lp" - 不是双辅音)
\w*[^aoyie][aoyie]([^aoyie])\1(ed|ing|ied)
Run Code Online (Sandbox Code Playgroud)
它正在使用RegexPal.com,但它不能在C#中工作(不匹配任何单词,在列表中返回0个单词)
我的代码:
List<Book_to_Word> allWords = (from f in db2.Book_to_Words.AsEnumerable() select f).ToList();
List<Book_to_Word> wordsNOTExist = (from f in allWords
where Regex.IsMatch(f.WordStr, @"^(\w*[^aoyie]+[aoyie]([^aoyie])(ed|ing|ied))$")
select f).ToList();
Run Code Online (Sandbox Code Playgroud)
当我不使用\ 1时工作.但是用单个辅音返回单词.
如何在Java中制作Enum类似于:
public enum Card {2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace};
Run Code Online (Sandbox Code Playgroud)
我试过{"2","3"......}.它也没有用