C# IsNullOrWhiteSpace() 方法用于检查指定字符串是否为空,或仅包含空白字符。它返回布尔值 True 或 False。
public static bool IsNullOrWhiteSpace(String str)
str:它是一个字符串参数,用于检查字符串中的空、空白。
它返回布尔值。
sing System; public class StringExample { public static void Main(string[] args) { string s1 = "Hello C#"; string s2 = ""; string s3 = " "; bool b1 = string.IsNullOrWhiteSpace(s1); bool b2 = string.IsNullOrWhiteSpace(s2); bool b3 = string.IsNullOrWhiteSpace(s3); Console.WriteLine(b1); // returns False Console.WriteLine(b2); // returns True Console.WriteLine(b3); // returns True } }
输出:
False True True