C# String IsNullOrWhiteSpace()
C# String IsNullOrWhiteSpace()
C# IsNullOrWhiteSpace() 方法用于检查指定的字符串是否为空,或仅由空白字符组成。它返回布尔值 True 或 False。
Signature
public static bool IsNullOrWhiteSpace(String str)
参数
str:是一个字符串参数,用于检查字符串中的空值、空格。
返回
返回布尔值。
C# String IsNullOrWhiteSpace() 方法示例
using 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
}
}
输出: