C#IsNullOrWhiteSpace()方法
IsNullOrWhiteSpace()C#中的方法用于指示指定的字符串是null,空还是仅由空格字符组成。
语法
public static bool IsNullOrWhiteSpace (string val);
上面的参数val是要测试的字符串。现在让我们看一个例子-
示例
现在让我们看一个例子:
using System;
public class Demo {
public static void Main() {
string str1 = null;
string str2 = String.Empty;
Console.WriteLine("Is string1 null or whitespace? = "+String.IsNullOrWhiteSpace(str1));
Console.WriteLine("Is string2 null or whitespace? = "+String.IsNullOrWhiteSpace(str2));
}
}输出结果
这将产生以下输出-
Is string1 null or whitespace? = True Is string2 null or whitespace? = True
示例
现在让我们来看另一个例子-
using System;
public class Demo {
public static void Main() {
string str1 = "\n";
string str2 = "Tim";
Console.WriteLine("Is string1 null or whitespace? = "+String.IsNullOrWhiteSpace(str1));
Console.WriteLine("Is string2 null or whitespace? = "+String.IsNullOrWhiteSpace(str2));
}
}输出结果
Is string1 null or whitespace? = True Is string2 null or whitespace? = False
热门推荐
10 小侄过生日祝福语简短
11 小店营业的祝福语简短
12 担任老师的祝福语简短
13 饮料吧台祝福语简短大气
14 公司新春搞笑祝福语简短
15 高情商敬酒祝福语简短
16 婚礼祝福语新郎妹妹简短
17 教师答辩通过祝福语简短
18 生女孩红包简短祝福语