C# IsNullOrWhiteSpace() 方法用於檢查指定的字符串是否為空,或僅由空白字符組成。它返回布爾值 True 或 False。
簽名
public static bool IsNullOrWhiteSpace(String str)
參數
str:它是一個字符串參數,用於檢查字符串中的空值和空格。
返回
它返回布爾值。
C# 字符串 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
}
}
輸出:
False True True
相關用法
- C# String IsNullOrEmpty()用法及代碼示例
- C# String IsNormalized()用法及代碼示例
- C# String IsInterned()用法及代碼示例
- C# String IndexOf()用法及代碼示例
- C# String Insert()用法及代碼示例
- C# String ToLower()用法及代碼示例
- C# String ToString()用法及代碼示例
- C# String Contains()用法及代碼示例
- C# String ToCharArray()用法及代碼示例
- C# String TrimEnd()用法及代碼示例
- C# String Concat()用法及代碼示例
- C# String GetTypeCode()用法及代碼示例
- C# String Equals()用法及代碼示例
- C# String Split()用法及代碼示例
- C# String SubString()用法及代碼示例
- C# String Normalize()用法及代碼示例
- C# String Compare()用法及代碼示例
- C# String LastIndexOfAny()用法及代碼示例
- C# String EndsWith()用法及代碼示例
- C# String Trim()用法及代碼示例
注:本文由純淨天空篩選整理自 C# String IsNullOrWhiteSpace()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。