Over a million developers have joined DZone.

Remove Duplicate Characters - C# (Case Sensitive)

·

Remove Duplicate characters from string using BitArray.

This is case-sensitive removal.

Func RemoveDuplicate = delegate(string s)
            {
                BitArray _arr = new BitArray(256);
                StringBuilder _sb = new StringBuilder();
                s = s.ToLower();
                for (int i = 0; i < s.Length; i++)
                {
                    if (_arr[(int)s[i]])
                    {
                        continue;
                    }
                    else
                    {
                        _arr[(int)s[i]] = true;
                        _sb.Append(s[i]);
                    }
                }
                return _sb.ToString();
            };
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}