小编use*_*406的帖子

正则表达式允许使用拉丁字母和数字,并不允许使用空格

我的正则表达式只允许使用拉丁字母和数字,并不允许使用空格。但是此表达式缺少存在空间的字符串。在我的代码中,我需要看到是非。但是我看到的是真实的。如何解决?

String str1="5asdfEDadgs2";
String str2 = "5 asdfgsadgs2";
String reg=@"^[a-zA-Z]|[0-9]|.*$"

bool res = Regex.Match(str1,reg). Success; //Must show true
bool res2 = Regex.Match(str2, reg).Success; //Must show false

Console.WriteLine(res);
Console.WriteLine(res2);
Run Code Online (Sandbox Code Playgroud)

c# regex

5
推荐指数
1
解决办法
4230
查看次数

多少次重复每个符号

你能帮我写LINQ来计算:字符串中每个符号的数量是多少?像这样?

String text="aaabbcccdde";
Dictionary<int,char> result=....//LINQ
foreach (var t in result)
{
  Console.WriteLine("Symbol {0} is met {1} times",t.symbol,t.times);
}
Run Code Online (Sandbox Code Playgroud)

c# linq string

2
推荐指数
1
解决办法
75
查看次数

标签 统计

c# ×2

linq ×1

regex ×1

string ×1