字符串问题 有N个文本,其中有S个文本包含字符串A求S的数量 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 读出文本,逐个字符查找,或者用kmp算法查找 int sum=0;for(循环N个文本){ if(N个文本.IndexOf('A')>0 sum++} 开始对楼主的问题不理解,还以为S已经是已知数了呢,lol。看了这个答案才明白,哎,老了。这个答案不错哦,应该能解决问题。 int sum=0;for(循环N个文本){ if(N个文本.IndexOf('A')>0 sum++}++ /// <summary> /// 获取目录下所有txt文件中eaquals文本重复的次数 /// </summary> /// <param name="path"></param> /// <param name="eaquals"></param> /// <returns></returns> private static int GetTextCount(string path,string eaquals) { int count = 0; foreach (string file in System.IO.Directory.GetFiles(path)) { string filepath = Path.Combine(path, file); if (File.Exists()&&Path.GetExtension(filepath).ToLower().CompareTo("txt")==0) { MatchCollection match=Regex .Matches(fs.ReadToEnd(),equals,RegexOptions.IgnoreCase|RegexOptions.Singleline); if (match.Count>0) { count+=match.Count; } } } } /// <summary> /// 获取目录下所有txt文件中eaquals文本重复的次数 /// </summary> /// <param name="path"></param> /// <param name="eaquals"></param> /// <returns></returns> private static int GetTextCount(string path,string eaquals) { int count = 0; StreamReader fs = null; foreach (string file in System.IO.Directory.GetFiles(path)) { string filepath = Path.Combine(path, file); fs = new StreamReader(filepath); if (File.Exists(filepath) && Path.GetExtension(filepath).ToLower().CompareTo(".txt") == 0) { MatchCollection match = Regex.Matches(fs.ReadToEnd(),string.Concat("[",eaquals,"]"), RegexOptions.IgnoreCase | RegexOptions.Singleline); if (match.Count>0) { count+=match.Count; fs.Dispose(); } } } return count; }修改了一下,这次可以了 GetTextCount(AppDomain.CurrentDomain.BaseDirectory, "Get")调用 如何知道对方是哪个网页放了自己的代码! 菜鸟问题~~待解决! rdlc报表 XML 动态的产生 c# CrystalReport如何获得FieldObject(数据组)的内容 请教asp.net程序打包的问题 escape/unescape问题,答案正确马上给分 做了两年数据库开发,烦了,有多少做网络开发的?给指个路吧 我怎样获取listView控件的Header的Rectangle属性? 请问用C#能不能开发ActiveX控件? C#中如何播放WAV声音文件呀? httpwebrequest抓取页面时返回404错误! 关于TreeView中Tag 类型转换
for(循环N个文本)
{
if(N个文本.IndexOf('A')>0
sum++
}
for(循环N个文本)
{
if(N个文本.IndexOf('A')>0
sum++
}++
/// 获取目录下所有txt文件中eaquals文本重复的次数
/// </summary>
/// <param name="path"></param>
/// <param name="eaquals"></param>
/// <returns></returns>
private static int GetTextCount(string path,string eaquals)
{
int count = 0;
foreach (string file in System.IO.Directory.GetFiles(path))
{
string filepath = Path.Combine(path, file);
if (File.Exists()&&Path.GetExtension(filepath).ToLower().CompareTo("txt")==0)
{
MatchCollection match=Regex .Matches(fs.ReadToEnd(),equals,RegexOptions.IgnoreCase|RegexOptions.Singleline);
if (match.Count>0)
{
count+=match.Count;
}
}
}
}
/// 获取目录下所有txt文件中eaquals文本重复的次数
/// </summary>
/// <param name="path"></param>
/// <param name="eaquals"></param>
/// <returns></returns>
private static int GetTextCount(string path,string eaquals)
{
int count = 0;
StreamReader fs = null;
foreach (string file in System.IO.Directory.GetFiles(path))
{
string filepath = Path.Combine(path, file);
fs = new StreamReader(filepath);
if (File.Exists(filepath) && Path.GetExtension(filepath).ToLower().CompareTo(".txt") == 0)
{
MatchCollection match = Regex.Matches(fs.ReadToEnd(),string.Concat("[",eaquals,"]"), RegexOptions.IgnoreCase | RegexOptions.Singleline);
if (match.Count>0)
{
count+=match.Count;
fs.Dispose();
}
}
}
return count;
}
修改了一下,这次可以了