String.IsNullOrWhiteSpace(String) Methode
Definition
Gibt an, ob eine angegebene Zeichenfolge null
ist, leer ist oder nur aus Leerzeichen besteht.Indicates whether a specified string is null
, empty, or consists only of white-space characters.
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
Parameter
- value
- String
Die zu testende Zeichenfolge.The string to test.
Gibt zurück
true
, wenn der value
-Parameter null
oder Empty ist oder wenn value
ausschließlich aus Leerzeichen besteht.true
if the value
parameter is null
or Empty, or if value
consists exclusively of white-space characters.
Beispiele
Im folgenden Beispiel wird ein Zeichen folgen Array erstellt und dann jedes Element des Arrays an die- IsNullOrWhiteSpace Methode weitergeleitet.The following example creates a string array, and then passes each element of the array to the IsNullOrWhiteSpace method.
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
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
Hinweise
IsNullOrWhiteSpace ist eine bequeme Methode, die dem folgenden Code ähnelt, mit dem Unterschied, dass Sie eine bessere Leistung bietet:IsNullOrWhiteSpace is a convenience method that is similar to the following code, except that it offers superior performance:
return String.IsNullOrEmpty(value) || value.Trim().Length == 0;
Return String.IsNullOrEmpty(value) OrElse value.Trim().Length = 0
Leerzeichen werden durch den Unicode-Standard definiert.White-space characters are defined by the Unicode standard. Die- IsNullOrWhiteSpace Methode interpretiert jedes Zeichen, das den Wert zurückgibt, true
Wenn es Char.IsWhiteSpace als Leerzeichen an die-Methode übermittelt wird.The IsNullOrWhiteSpace method interprets any character that returns a value of true
when it is passed to the Char.IsWhiteSpace method as a white-space character.