Remove duplicate characters in a string in C#

Saratvaddilli
Posted by Saratvaddilli under C# category on | Points: 40 | Views : 4917
        Func<string, string> RemoveDuplicate = delegate(string s)
{
BitArray _arr = new BitArray(256);
StringBuilder _sb = new StringBuilder();
s = s.ToLower();
for (int j = 0; j < s.Length; j++)
{
if (_arr[(int)s[j]])
{
continue;
}
else
{
_arr[(int)s[j]] = true;
_sb.Append(s[j]);
}
}
return _sb.ToString();
};

Comments or Responses

Posted by: T.Saravanan on: 12/30/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi,

Could you explain your code little bit?

Note: Kindly modify the for loop variable instead of "i". Because in DNF Square Brace of "i" is consider as italic format.

Login to post response