C# IsNullOrWhiteSpace() 方法
C# 中的 IsNullOrWhiteSpace() 方法用于指示指定的字符串是否为 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 = "
";
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP