String.IsNullOrWhiteSpace(String) Yöntem

Tanım

Belirtilen dizenin null, boş veya yalnızca boşluk karakterlerinden mi oluştuğuna işaret eder.

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 etmek için dize.

Döndürülenler

truevalue 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 , aşağıdaki koda benzer bir kolaylık yöntemidir, ancak üstün performans sunar:

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öntemine boşluk karakteri olarak geçirildiğinde Char.IsWhiteSpace değerini true döndüren herhangi bir karakteri yorumlar.

Şunlara uygulanır

Ayrıca bkz.