你怎么能删除重复字符串中的字符? [英] How can you remove duplicate characters in a string?
本文介绍了你怎么能删除重复字符串中的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要实现一个函数,接受一个字符串作为输入,并发现从该字符串中的非重复的字符。
I have to implements a function that takes a string as an input and finds the non-duplicate character from this string.
因此,一个例子是,如果我通过字符串str =DHCD将返回DHC
或str2的=KLKLHHMO将返回KLHMO
So an an example is if I pass string str = "DHCD" it will return "DHC" or str2 = "KLKLHHMO" it will return "KLHMO"
推荐答案
一个LINQ的方法:
public static string RemoveDuplicates(string input)
{
return new string(input.ToCharArray().Distinct().ToArray());
}
这篇关于你怎么能删除重复字符串中的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文