小编Vil*_*Vil的帖子

将MatchCollection转换为字符串数组

有没有比这更好的方法将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)抛出异常:

源数组中至少有一个元素无法转换为目标数组类型.

c# regex arrays

70
推荐指数
3
解决办法
5万
查看次数

Regex.Match在c#中的双辅音

我有很多单词的清单.我需要的是找到以"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时工作.但是用单个辅音返回单词.

c# regex

6
推荐指数
2
解决办法
962
查看次数

枚举中包含字符串值的int值

如何在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"......}.它也没有用

java enums

4
推荐指数
1
解决办法
90
查看次数

标签 统计

c# ×2

regex ×2

arrays ×1

enums ×1

java ×1