怎样可以删除字符串中重复的字符!!!(vb.net)

山海996 2008-07-11 11:07:42

譬如:输入为--a,d,f,s,f,a
输出则变为---d,s
多谢!
...全文
639 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
山海996 2008-07-11
  • 打赏
  • 举报
回复
多谢关注,上面的问题已经解决了...
贴出来共享,THS
Dim str1 As String = "a;d;f;s;f;a"
Dim strs() = str1.Split(";")
Dim str2 As String

For i = 0 To UBound(strs)
For j = 0 To i - 1
If strs(i) = strs(j) Then
strs(i) = ""
strs(j) = ""
End If
Next
Next
For i = 0 To UBound(strs)
If strs(i) <> "" Then
str2 = str2 + " " + strs(i)
End If
Next
str2 = str2.Replace(" ", ";")
tfrtfr 2008-07-11
  • 打赏
  • 举报
回复
简单的算法题嘛,给你一个,算法够不够好,就不管了。
static void Main(string[] args)
{
string input = "a,d,f,s,f,a";
string[] ss= input.Split(new char[] { ',' });
string ouput="";
Dictionary<string,int> list = new Dictionary<string,int>();
foreach (string s in ss)
{
if (list.ContainsKey(s))
list[s]++;
else
list[s] = 1;
}
foreach (KeyValuePair<string,int> l in list)
{
if (l.Value == 1)
ouput += l.Key + ",";
}
ouput = ouput.TrimEnd(new char[] {',' });
Console.WriteLine(ouput);
}

16,717

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧