码迷,mamicode.com
首页 > Windows程序 > 详细

c# 去除字符串中重复字符

时间:2018-01-19 11:47:01      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:需要   重复数据   去除   src   post   字符串   tool   gif   重复数   

https://www.cnblogs.com/LuoEast/p/7886297.html

 

 

1.在写程序中经常操作字符串,需要去重,以前我的用方式利用List集合和 contains去重复数据代码如下:

技术分享图片
技术分享图片
技术分享图片
技术分享图片
 1     string test="123,123,32,125,68,9565,432,6543,343,32,125,68";
 2      string[] array = test.Split(,);
 3      List<string> list = new List<string>();
 4      foreach (string item in array )
 5      {
 6        if (!list.Contains(item ))
 7            {
 8                list.Add(item);
 9            }
10      }
技术分享图片
技术分享图片

 

技术分享图片
技术分享图片

2.现在我推荐大家使用一下方式去重复数据

1. string test="123,123,32,125,68,9565,432,6543,343,32,125,68";
2.string test1= String.Join("",test.Split(,‘).Disctinct());

c# 去除字符串中重复字符

标签:需要   重复数据   去除   src   post   字符串   tool   gif   重复数   

原文地址:https://www.cnblogs.com/LuoEast/p/8315477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!