C#删除字符串中重复字符的方法
本文实例讲述了C#删除字符串中重复字符的方法。分享给大家供大家参考。具体实现方法如下:
#region删除重复字符 strings="sdfffffsrlkjesgljfdg03940864e5=_0R9DTGR98YUI\\|||'\\???fdf///"; Response.Write("<br/>String:"+s+"<br/>Result:"); IEnumerable<char>distinctList=s.Distinct(); foreach(charaindistinctList) { Response.Write(a.ToString()); } //使用移除法 for(inti=0;i<s.Length;i++) { while(s.IndexOf(s.Substring(i,1))!=s.LastIndexOf(s.Substring(i,1))) { s=s.Remove(s.LastIndexOf(s.Substring(i,1)),1); } } Response.Write("<hr/>Result:"+s); #endregion
希望本文所述对大家的C#程序设计有所帮助。