SoFunction
Updated on 2025-03-08

C# method to clear spaces in strings

/// <summary>
/// Clear the spaces in the string
/// </summary>
/// <param name="str">Strings to be processed</param>
/// <returns> Processed string</returns>
public static string ExceptBlanks(this string str)
{
    int _length = ;
    if (_length > 0)
    {
 StringBuilder _builder = new StringBuilder(_length);
 for (int i = 0; i < ; i++)
 {
     char _c = str[i];
     //switch (_c)
     //{
     //    case '\r':
     //    case '\n':
     //    case '\t':
     //    case ' ':
     //        continue;
     //    default:
     //        _builder.Append(_c);
     //        break;
     //}
     if (!(_c))
  _builder.Append(_c);
 }
 return _builder.ToString();
    }
    return str;
}