字符串是以,相隔的数字的形式,如何去除其中相同的数字? 比如:1,2,2,6,78,9,10,6变为1,2,6,78,9,10这个如何写(c#) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string source = "1,2,2,6,78,9,10,6"; string result = ""; System.Collections.Generic.List<string> stringList = new System.Collections.Generic.List<string>(); string[] strList = source.Split(',',StringSplitOptions.RemoveEmptyEntries); foreach (string str in stringList) { if (!stringList.Contains(str)) { stringList.Add(str); result += str + ","; } } //执行循环后result="1,2,6,78,9,10,6,"; result.Remove(result.Length - 1);//移除最后一个',',result="1,2,6,78,9,10,6"; string str = "1,2,2,6,78,9,10,6"; string newstr=""; List<string> str1 = new List<string>(); foreach (string s in str.Split(',')) { if (!str1.Contains(s)) str1.Add(s); } foreach (string s in str1) { newstr += s+","; } newstr = newstr.Remove(newstr.Length - 1); http://topic.csdn.net/t/20041210/14/3633655.html看这个帖子8楼的答案! 根据IP得到所在的地区名称? asp.net在页面上怎么实现信息滚动的效果啊 CNblog问题,帮我看下. 我的网站浏览过程中点IE的后退按纽无效。 asp.net部署问题(急!!) 简单问题(弹出确认对话框) IIS7.0怎么启用集成windows身份验证啊? 如何把 name 转换为 int数组参数 加入下面的SQL语句 请问如何用linkButton连接一个页 vs.net 2003 final beta火热下载!!!! 在asp.net 用c#调用sql server2000存储过程,没有成功,请指教. 关于dropdownlist做成一条线效果
string source = "1,2,2,6,78,9,10,6";
string result = "";
System.Collections.Generic.List<string> stringList = new System.Collections.Generic.List<string>();
string[] strList = source.Split(',',StringSplitOptions.RemoveEmptyEntries);
foreach (string str in stringList)
{
if (!stringList.Contains(str))
{
stringList.Add(str);
result += str + ",";
}
}
//执行循环后result="1,2,6,78,9,10,6,";
result.Remove(result.Length - 1);//移除最后一个',',result="1,2,6,78,9,10,6";
string newstr="";
List<string> str1 = new List<string>(); foreach (string s in str.Split(','))
{
if (!str1.Contains(s))
str1.Add(s);
}
foreach (string s in str1)
{
newstr += s+",";
}
newstr = newstr.Remove(newstr.Length - 1);
看这个帖子8楼的答案!