What's the most efficient way to determine whether an untrimmed string is empty in C#?

前端 未结 8 1591

I have a string that may have whitespace characters around it and I want to check to see whether it is essentially empty.

There are quite a few ways to do this:

8条回答
  •  失恋的感觉
    2020-12-16 00:08

    public static bool IsNullOrEmpty(this String str, bool checkTrimmed)
    {
      var b = String.IsNullOrEmpty(str);
      return checkTrimmed ? b && str.Trim().Length == 0 : b;
    }
    

提交回复
热议问题