C# 判断字符串里面有多少个字符
可以使用 Count 方法来判断字符串中包含多少个指定字符。
以下是一个示例代码,用于判断字符串中包含多少个 '/' 字符。
using System;
class Program
{
static void Main(string[] args)
{
string str = "C:/Program Files/Microsoft";
int count = str.Count(c => c == '/');
Console.WriteLine("字符串中包含 {0} 个 '/' 字符。", count);
}
}
输出结果为:
字符串中包含 2 个 '/' 字符。
原文地址: http://www.cveoy.top/t/topic/jcT9 著作权归作者所有。请勿转载和采集!