解决方案 »
- 关于对第三方网站进行点击统计,留言的设计
- GridView 中itemtemplate 换行
- 求个设置IIS虚拟目录访问权限的方法
- .net动态调用视频URL
- 需要一份asp.net基础的考试试卷(基于C#语言的)
- 使用ASP.NET在服务器c:\public生成了excel文件,但是想生成完后,就打开此文件,如何做
- 一个搞不明白的问题,求助大家!
- 使用GridView显示数据,怎么增加一字段使该字段通过计算得来的结果同其它字段一样显示出来
- 删除datagrid的第一行是出错,请问大家是怎么处理的?
- 数据库问题
- 使用谷歌地图 IE6下GBrowserIsCompatible() 缺少对象
- sql数据库缓存依赖
string str = "啊我是中国人哦我是外国人啊我是韩国人嘿我是美国人哈我是中国人喂我是英国人呦我是中国人嘘我是外国人";
int num = 5;
int maxcount = 0;
string maxstr = "";
for (int i = 0; i + num < str.Length; i++)
{
string tempvalue = str.Substring(i, num);
string tempstr = str;
int count = 0;
while (tempstr.Length > 0)
{
if (tempstr.IndexOf(tempvalue) > 0)
{
count++;
tempstr = tempstr.Substring(tempstr.IndexOf(tempvalue) + num);
}
else
break;
}
if (count > maxcount)
{
maxcount = count;
maxstr = tempvalue;
}
}
Response.Write(maxstr);
{
int _count;
string _value; public max(int count, string value)
{
this._count = count;
this._value = value;
} public int Count
{
get { return _count; }
set { _count = value; }
} public string Value
{
get { return _value; }
set { _value = value; }
}
} public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = "啊我是中国人哦我是外国人啊我是韩国人嘿我是美国人哈我是中国人喂我是英国人呦我是中国人嘘我是外国人嘿我是外国人";
int num = 5;
List<max> list = new List<max>();
list.Add(new max(0, ""));
for (int i = 0; i + num < str.Length; i++)
{
string tempvalue = str.Substring(i, num);
string tempstr = str.Substring(i);
int count = 0;
while (tempstr.Length > 0)
{
if (tempstr.IndexOf(tempvalue) >= 0)
{
count++;
tempstr = tempstr.Substring(tempstr.IndexOf(tempvalue) + num);
}
else
break;
}
if (count > list[0].Count)
{
list.Clear();
list.Add(new max(count, tempvalue));
}
else if (count == list[0].Count)
list.Add(new max(count, tempvalue));
}
}
}
这段可以获得多个数量相同的放在list里
string str = "啊我是中国人哦我是外国人啊我是韩国人嘿我是美国人哈我是中国人喂我是英国人呦我是中国人嘘我是外国人我是外国人";
int num = 5;
int count = 0;
string tempsub = string.Empty;
string result = string.Empty;
Regex r = null;
for (int i = 0; i + num < str.Length; i++)
{
tempsub = str.Substring(i, num);
r = new Regex(tempsub);
MatchCollection mc = r.Matches(str);
if (mc.Count > count)
{
count = mc.Count;
result = tempsub;
}
else if (mc.Count == count)
{
if (!result.Contains(tempsub))
{
result = result + "," + tempsub;
}
} }
MessageBox.Show(result); }
次数相同的多个字符串用 , 分割
23456
34567
成到一个hash表里 没得就新建 有了就加一
arr[i]=str.substring(i,5);
2、对数据进行排序
arr.sorts()
3、统计相同的个数。
Create table G
(
Col1 varchar(200)
);insert into G (Col1) values('啊');
insert into G (Col1) values('我');
insert into G (Col1) values('啊');
insert into G (Col1) values('我');
insert into G (Col1) values('啊');
insert into G (Col1) values('我');
insert into G (Col1) values('啊');
insert into G (Col1) values('我');
insert into G (Col1) values('啊');
insert into G (Col1) values('我');
insert into G (Col1) values('啊');
insert into G (Col1) values('韩');
insert into G (Col1) values('嘿');
insert into G (Col1) values('我');select col1, count(*) from G group by Col1;Col1 count
啊 6
韩 1
嘿 1
我 6这只是个简单的演示,真正用的时候写存储过程,建临时表即可。