SoFunction
Updated on 2025-03-07

C# traversal to delete duplicate characters in string

This article describes the C# method of traversing and deleting duplicate characters in strings. Share it for your reference. The specific implementation method is as follows:

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

I hope this article will be helpful to everyone's C# programming.