C# 在给定字符串中查找u的唯一匹配项
首先让我们粘贴一个代码,然后我会告诉你我的要求C# 在给定字符串中查找u的唯一匹配项,c#,C#,首先让我们粘贴一个代码,然后我会告诉你我的要求 void Main() { String someString = "Fill ________ and ______ this"; char someChar = '_'; int count = 0; for (int i = 0; i < someString.Length; i++) { if (someString[i] == someChar) {
void Main()
{
String someString = "Fill ________ and ______ this";
char someChar = '_';
int count = 0;
for (int i = 0; i < someString.Length; i++)
{
if (someString[i] == someChar)
{
count++;
}
}
}
void Main()
{
String someString=“填充和填充”;
char someChar='u';
整数计数=0;
for(int i=0;i
在这段代码中,我有两个占位符,用x表示。
如果\u
一次出现超过2次,则该字符串被视为该字符串中的占位符
输入
{3,}
是一种模式,它至少匹配三个下划线,因此:
Regex.Matches("Fill ________ and ______ this", "_{3,}").Count
2
Regex.Matches("There are 1 single _ , 1 double __ and 1 tripple ___ here.", "_{3,}").Count
1
尽管“现在你有两个问题”,但这可以用一个简单的方法解决{3,}
是一种模式,它至少匹配三个下划线,因此:
Regex.Matches("Fill ________ and ______ this", "_{3,}").Count
2
Regex.Matches("There are 1 single _ , 1 double __ and 1 tripple ___ here.", "_{3,}").Count
1
为什么不搜索字符串是否包含三重下划线?嗯,问题是什么?可以使用正则表达式来解决这个问题,编写一个模式来匹配所有“3个或更多连续下划线”非常简单,为什么不搜索字符串是否包含三重下划线?嗯,问题是什么?您可以使用正则表达式来解决这个问题,编写一个模式来匹配所有“3个或更多连续下划线”非常简单