<分区>
Possible Duplicate:
How would you count occurences of a string within a string (C#)?
我想检查一个字符串是否包含 2 个东西..
String hello = "hellohelloaklsdhas";
if hello.Contains(*hello 2 Times*); -> True
我该如何解决这个问题?
<分区>
Possible Duplicate:
How would you count occurences of a string within a string (C#)?
我想检查一个字符串是否包含 2 个东西..
String hello = "hellohelloaklsdhas";
if hello.Contains(*hello 2 Times*); -> True
我该如何解决这个问题?
最佳答案
你可以使用正则表达式:)
return Regex.Matches(hello, "hello").Count == 2;
这与模式 "hello"
的字符串 hello
匹配,如果计数为 2,则返回 true。
关于c# if String 包含 2 "hallo",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8053462/