c# if String 包含 2 "hallo"

标签 c# string

<分区>

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/

相关文章:

泛型类中的 c# 方法仅适用于某些类型

java - 如何分隔java字符串的各个部分?

c# - jquery ajax返回异常(请求格式无效)

iphone - 如何重新排列 char* 中的字符?

c - C中任意长度的字符串

Java - 将字符串与字符串数组进行匹配

java - 如何在另一个字符串下面打印几个字符串?

c# - GetComponent 返回 null

c# - 如何在 C# .net 中管理图书馆管理系统中的学生和图书发行关系?

c# - 列出 FTP 目录中的前 N ​​个文件