String.IsNullOrWhiteSpace(String) 메서드

정의

지정된 문자열이 null이거나 비어 있거나 공백 문자로만 구성되어 있는지를 나타냅니다.

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

매개 변수

value
String

테스트할 문자열입니다.

반환

true 매개 변수가 value 또는 null이거나, Empty가 모두 공백 문자로 구성되어 있으면 value입니다.

예제

다음 예제에서는 문자열 배열을 만든 다음 배열의 각 요소를 메서드에 IsNullOrWhiteSpace 전달합니다.

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

설명

IsNullOrWhiteSpace 는 뛰어난 성능을 제공한다는 점을 제외하고 다음 코드와 유사한 편리한 방법입니다.

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

공백 문자는 유니코드 표준에 의해 정의됩니다. 메서드는 IsNullOrWhiteSpace 메서드에 전달 Char.IsWhiteSpace 될 때 값을 true 반환하는 모든 문자를 공백 문자로 해석합니다.

적용 대상

추가 정보