String.IsNullOrWhiteSpace(String) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Azt jelzi, hogy egy megadott sztring nullüres-e, vagy csak szóköz karakterekből áll.
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
Paraméterek
- value
- String
A tesztelni kívánt sztring.
Válaszok
true ha a value paraméter vagy nullEmpty, vagy ha value kizárólag szóköz karakterekből áll.
Példák
Az alábbi példa létrehoz egy sztringtömböt, majd átadja a tömb minden elemét a IsNullOrWhiteSpace metódusnak.
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
Megjegyzések
IsNullOrWhiteSpace a következő kódhoz hasonló kényelmi módszer, azzal a kivételrel, hogy kiváló teljesítményt nyújt:
return String.IsNullOrEmpty(value) || value.Trim().Length == 0;
String.IsNullOrEmpty value || value.Trim().Length = 0
Return String.IsNullOrEmpty(value) OrElse value.Trim().Length = 0
A szóköz karaktereket a Unicode szabvány határozza meg. A IsNullOrWhiteSpace metódus minden olyan karaktert értelmez, amely visszaadja a metódusnak true átadott értéket Char.IsWhiteSpace szóköz karakterként.