C# 实现字符串去重
方法一 注:需要.net 3.5框架的支持
string s = "101,102,103,104,105,101,102,103,104,105,106,107,101,108";
s = string.Join(",", s.Split(',').Distinct().ToArray());
方法二
class Program
{
static void Main(string[] args)
{
string result="";
string str = "101,102,103,104,105,101,102,103,104,105,106,107,101,108";
ArrayList list = array(str);
for (int i = ; i < list.Count;i++)
{
if (i == list.Count - )
{
result += list[i];
}
else
{
result += list[i] + ",";
}
}
Console.WriteLine(result); Console.ReadKey();
} static ArrayList array(string str)
{
ArrayList aimArr = new ArrayList();
ArrayList strArr = new ArrayList();
string [] strs=str.Split(',');
foreach (string s in strs)
{
strArr.Add(s);
}
for (int i = ; i < strs.Length; i++)
{
if (!aimArr.Contains(strs[i]))
{
aimArr.Add(strs[i]);
}
}
return aimArr;
}
} //101,102,103,104,105,106,107,108
方法三:使用正则
string input = "101,102,103,104,105,101,102,103,104,105,106,107,101,108";
input = Regex.Replace(input + ",", @"(?:([^,]+,))(?=.*?\1)", "");
Console.WriteLine(input.Substring(,input.Length-));
C# 实现字符串去重的更多相关文章
- 2015.4.25-2015.5.1 字符串去重,比例圆设计,中奖机和canvas橡皮擦效果等
1.字符串去重,html模板取值 2.javascript正则表达式之$1...$9 3.jquery插件 4.返回上一页并刷新 解决方法: <a href ="javas ...
- JS实现字符串去重,数组去重
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- c++ 字符串去重
##### c++ 字符串去重 == 需求 == * 编写一个字符串过滤函数,若字符串出现多个相同的字符,将不是首次出现的字符过滤掉. > 输入:"apache" 输出:&q ...
- js字符串去重
js字符串去重: 1. 去掉字符串前后所有空格: function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); } ...
- js 数组&字符串 去重
Array.prototype.unique1 = function() { var n = []; //一个新的临时数组 for(var i = 0; i < this.length; i++ ...
- 面试题常考&必考之--js中的数组去重和字符串去重
1.引入:首先得知道数组没有可以直接去重的方法,即直接[].unique()是不支持的, 会报“Uncaught TypeError: [].unique is not a function”错误, ...
- c++实现哈夫曼树,哈夫曼编码,哈夫曼解码(字符串去重,并统计频率)
#include <iostream> #include <iomanip> #include <string> #include <cstdlib> ...
- C#中有关字符串去重的解决方案
今天在群里看到一个同学的面试题 题目中有一个这样的要求 //本地有个文档文件a.txt里面包含的内容分为一段字符串"abacbacde"请编写一个程序,获取文件得到对应的内容,并对 ...
- C语言对字符串去重
# include <stdio.h> # include <string.h> char * getNewChar(char * str,char * newStr); in ...
- 高级数据结构及应用 —— 使用 bitmap 进行字符串去重
bitmap 即为由单个元素为 boolean(0/1, 0 表示未出现,1 表示已经出现过)的数组. 如果C/C++ 没有原生的 boolean 类型,可以用 int 或 char 来作为 bitm ...
随机推荐
- 团队项目 SRS文档
一:实验内容:用例模型的建立 简介: 图书管理系统是使用计算机实现图书大量信息处理的电子档案管理系统,在本系统中主要满足借书者.图书管理员和系统管理员3方面的需求.对借书者来说主要是查询个人信息.查询 ...
- 一页纸商业计划书 (Business Plan) 模板(转载)
本文转载自:https://blog.eood.cn/business-plan 假如你也有一个 idea ,但是还处于想法阶段,这个商业计划书模板能够帮你理清思路. 这个一页 BP 模板简单实用,分 ...
- [自娱自乐] 3、超声波测距模块DIY笔记(三)
前言 上一节我们已经研究了超声波接收模块并自己设计了一个超声波接收模块,在此基础上又尝试用单片机加反相器构成生成40KHz的超声波发射电路,可是发现采用这种设计的发射电路存在严重的发射功率太低问题,对 ...
- [BTS] System.Xml.Schema.XmlSchemaException: The complexType has already been declared when generate IDoc schema.
I use wcf-sap adapter for generate the schema of IDoc that named "YHREMPMASTER". but throw ...
- 样式中的url加载探疑
当一个项目多人维护,特别是接手别人的项目,而项目又在改之又改的基础上再改,我一直遵循,别人的样式我不动的原则,尽量不因为一时不察,导致整站或部分页面出现错位的现象,因些在修改样式与写样式时都是在原有的 ...
- Leetcode 155 Min Stack
题意:设计一个能输出栈内最小值的栈 该题设计两个栈,一个栈是正常的栈s,而另一个是存最小值的栈sm 在push时要判断sm是否为空,如果为空或者非空但是栈顶元素大于等于插入值的 需要在sm中插入x 同 ...
- A Xamarin.Forms Infinite Scrolling ListView
from:http://www.codenutz.com/lac09-xamarin-forms-infinite-scrolling-listview/ The last few months ha ...
- C#:WebBrowser控件设置代理IP访问网站【附源码】
软件截图 源码下载 http://download.csdn.net/detail/php_fly/8041731
- OpenBTS的安装(转)
OpenBTS source code可以在这里下载:http://sourceforge.net/projects/openbts/ OpenBTS入门的各种问题可以在这里找到答案:http://g ...
- int android.graphics.Bitmap.getRowBytes()
int android.graphics.Bitmap.getRowBytes() Return the number of bytes between rows in the bitmap's pi ...