我的正则表达式只允许使用拉丁字母和数字,并不允许使用空格。但是此表达式缺少存在空间的字符串。在我的代码中,我需要看到是非。但是我看到的是真实的。如何解决?
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) 你能帮我写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)