Check if string is empty or all spaces in C#

前端 未结 5 833
说谎
说谎 2020-12-09 14:32

How to easily check if a string is blank or full of an undetermined amount of spaces, or not?

5条回答
  •  自闭症患者
    2020-12-09 15:12

    If it's already known to you that the string is not null, and you just want to make sure it's not a blank string use the following:

    public static bool IsEmptyOrWhiteSpace(this string value) =>
      value.All(char.IsWhiteSpace);
    

提交回复
热议问题