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매개 변수가 valuenull 있거나 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 메서드에 전달될 때의 true 값을 반환하는 Char.IsWhiteSpace 문자를 공백 문자로 해석합니다.

적용 대상

추가 정보