假如有一字符串(001,002,001,003,002,001,003)如何能筛选出相同的,最后只得到001,002,003
解决方案 »
- Oracle 日期转换问题
- C#初学者问题
- 请问如何删除磁盘下某种格式的文件?
- float.Parse("99999999")结果为100000000,float最大能表示的整数是多少?
- 在HTTPS下,如何用 POST 实现传输 XML ?
- ???问一个用户控件使用问题???
- 使用 OleDb如何访问设置了访问密码和修改密码的excel文件?
- 高手帮忙哈,关于WebBrowser的几个问题。
- 如何获得AxWebBrowser控件前进、后退的状态?
- c#调用oracle存储过程的问题
- WinForm里生成TextBox的TextChanged如何生成?
- C#中如何通过SortedList获取文件的最后修改时间
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Net;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
string str = "(001,002,001,003,002,001,003)";
str = str.Substring(1, str.Length - 2);
var result=from s in str.Split(',') group s by s into g select g.Key;
foreach (var g in result) {
Console.WriteLine(g);
}
}
}
}
str = str.Substring(1, str.Length - 2);
string[] strA = str.Split(new char[]{','});
ArrayList al = new ArrayList();
foreach (string str1 in strA)
{
if (!al.Contains(str1)) al.Add(str1);
}al里就是你要的东西。
string[] arr = ss.Split(',');
string reVal = string.Empty;
for (int i = 0; i < arr.Length; i++)
{
if (!reVal.Contains(arr[i]))
{
reVal += arr[i]+",";
}
}
reVal = reVal.Substring(0, reVal.Length - 1);
{
////当combobox弹出DropDown下拉框时,将 olvColumnGroupID得组加入到下拉列表,并添加 All选项
if (cmd.ListObjectPlayer.Count > 0)
{
List<string> GroupsStr = new List<string>();
GroupsStr.Add("All");
for (int n = 0; n < cmd.ListObjectPlayer.Count; n++)
{
GroupsStr.Add(cmd.ListObjectPlayer[n].GroupID);
}
GroupsStr.Sort();
List<String> Groupsorter = new List<string>();
for (int gs = 0; gs < GroupsStr.Count; gs++)
{
if (gs == 0)
{
Groupsorter.Add(GroupsStr[gs]);
}
else if (GroupsStr[gs] != GroupsStr[gs - 1])
{
Groupsorter.Add(GroupsStr[gs]);
}
}
Groupsorter.Sort();
comboBoxGroupSortView.Items.Clear();
for (int s = 0; s < Groupsorter.Count; s++)
{
comboBoxGroupSortView.Items.Add(Groupsorter[s]);
}
}
}
ListObjectPlayer是List<Player> 数组对象 ,Player有 GroupID,PlayerID,MAC等字段
在Objectlistview一个对象的listview控件里有你说的(001,002,001,003,002,001,003)组列,把这个加到comboBoxGroupSortView里
显示
001,002,003,all
using System;namespace ConsoleApplication1
{
class Program
{
static void Main()//这是我认为的效率最高的一种
{
string ss = "001,002,001,003,002,001,003";
HashTable ht = new HashTable();
string[] temp = ss.Split(',');
foreach(string s in temp)
{
ht[s] = s;
}
foreach(string s in ht.Keys)
{
Console.WriteLine(s);
}
}
}
}