String.IsNullOrWhiteSpace(String) Yöntem

Tanım

Belirtilen dizenin null, boş mu yoksa yalnızca boşluk karakterlerinden mi oluştuğudur gösterir.

public:
 static bool IsNullOrWhiteSpace(System::String ^ value);
public static bool IsNullOrWhiteSpace(string value);
public static bool IsNullOrWhiteSpace(string? value);
static member IsNullOrWhiteSpace : string -> bool
Public Shared Function IsNullOrWhiteSpace (value As String) As Boolean

Parametreler

value
String

Test için dize.

Döndürülenler

true value parametresi null veya Emptyise veya yalnızca boşluk karakterlerinden oluşuyorsavalue.

Örnekler

Aşağıdaki örnek bir dize dizisi oluşturur ve ardından dizinin her öğesini yöntemine IsNullOrWhiteSpace geçirir.

using System;

public class Example
{
   public static void Main()
   {
      string[] values = { null, String.Empty, "ABCDE", 
                          new String(' ', 20), "  \t   ", 
                          new String('\u2000', 10) };
      foreach (string value in values)
         Console.WriteLine(String.IsNullOrWhiteSpace(value));
   }
}
// The example displays the following output:
//       True
//       True
//       False
//       True
//       True
//       True
open System

let values = 
    [| null; String.Empty; "ABCDE"
       String(' ', 20); "  \t   "
       String('\u2000', 10) |]

for value in values do
    printfn $"{String.IsNullOrWhiteSpace value}"
// The example displays the following output:
//       True
//       True
//       False
//       True
//       True
//       True
Module Example
   Public Sub Main()
      Dim values() As String = { Nothing, String.Empty, "ABCDE", 
                                 New String(" "c, 20), "  " + vbTab + "   ", 
                                 New String(ChrW(&h2000), 10) }
      For Each value As String In values
         Console.WriteLine(String.IsNullOrWhiteSpace(value))
      Next
   End Sub
End Module
' The example displays the following output:
'       True
'       True
'       False
'       True
'       True
'       True

Açıklamalar

IsNullOrWhiteSpace , üstün performans sağlaması dışında aşağıdaki koda benzer bir kolaylık yöntemidir:

return String.IsNullOrEmpty(value) || value.Trim().Length == 0;
String.IsNullOrEmpty value || value.Trim().Length = 0
Return String.IsNullOrEmpty(value) OrElse value.Trim().Length = 0

Boşluk karakterleri Unicode standardı tarafından tanımlanır. yöntemi, IsNullOrWhiteSpace yönteme boşluk karakteri olarak geçirildiğinde true değerini Char.IsWhiteSpace döndüren herhangi bir karakteri yorumlar.

Şunlara uygulanır

Ayrıca bkz.