當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C# String IsNullOrWhiteSpace()用法及代碼示例

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 IsNullOrWhiteSpace()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。