c# 统计字符串
来源:百度知道 编辑:UC知道 时间:2024/06/25 07:16:12
用StreamReader读出文本内容后,想统计出在此文本内容中一个字符串所出现的次数,请问代码怎么写?
正则表达式?不懂...,求教简而易懂的,
ci= 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] == 'A')//这一句在调试时出错,是[]?
{
ci++;
}
}
正则表达式?不懂...,求教简而易懂的,
ci= 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] == 'A')//这一句在调试时出错,是[]?
{
ci++;
}
}
引用
using System.Text.RegularExpression;
得到结果
int getnum=Regex.Matches(sr.ToString(),"A").Count;
ci= 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] == 'A')
{
ci++;
}
}
不懂学啊,迟早要接触的东西。
using System.Text.RegularExpression;
Regex.Matches(sr.ToString(),"A").Count
long ci= 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] == 'A')//这一句在调试时出错,是[]?
{
ci++;
}
}
你没给 ci 定义类型
我运行就好用!
easy
ci= 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i].Equal("A"))//这一句在调试时出错,是[]?
{
ci++;
}
}