String.IsNullOrEmpty メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim value As String Dim returnValue As Boolean returnValue = String.IsNullOrEmpty(value)
戻り値
value パラメータが null 参照 (Visual Basic では Nothing) または空の文字列 ("") の場合は true。それ以外の場合は false。

IsNullOrEmpty メソッドを使用すると、String が null 参照 (Visual Basic では Nothing) であるかどうかと、値が Empty であるかどうかを一度に判定できます。

3 つの文字列に対し、それぞれが空の文字列、または null 参照 (Visual Basic では Nothing) であるかを確認するコード例を次に示します。
' This example demonstrates the String.IsNullOrEmpty() method Imports System Class Sample Public Shared Sub Main() Dim s1 As String = "abcd" Dim s2 As String = "" Dim s3 As String = Nothing Console.WriteLine("String s1 {0}.", Test(s1)) Console.WriteLine("String s2 {0}.", Test(s2)) Console.WriteLine("String s3 {0}.", Test(s3)) End Sub 'Main Public Shared Function Test(s As String) As [String] If [String].IsNullOrEmpty(s) = True Then Return "is null or empty" Else Return String.Format("(""{0}"") is not null or empty", s) End If End Function 'Test End Class 'Sample ' 'This example produces the following results: ' 'String s1 ("abcd") is not null or empty. 'String s2 is null or empty. 'String s3 is null or empty. '
// This example demonstrates the String.IsNullOrEmpty() method using System; class Sample { public static void Main() { string s1 = "abcd"; string s2 = ""; string s3 = null; Console.WriteLine("String s1 {0}.", Test(s1)); Console.WriteLine("String s2 {0}.", Test(s2)); Console.WriteLine("String s3 {0}.", Test(s3)); } public static String Test(string s) { if (String.IsNullOrEmpty(s) == true) return "is null or empty"; else return String.Format("(\"{0}\") is not null or empty", s); } } /* This example produces the following results: String s1 ("abcd") is not null or empty. String s2 is null or empty. String s3 is null or empty. */
// This example demonstrates the String.IsNullOrEmpty() method using namespace System; String^ Test( String^ s ) { if ( String::IsNullOrEmpty( s ) == true ) return "is null or empty"; else return String::Format( "(\"{0}\") is not null or empty", s ); } int main() { String^ s1 = "abcd"; String^ s2 = ""; String^ s3 = nullptr; Console::WriteLine( "String s1 {0}.", Test( s1 ) ); Console::WriteLine( "String s2 {0}.", Test( s2 ) ); Console::WriteLine( "String s3 {0}.", Test( s3 ) ); } /* This example produces the following results: String s1 ("abcd") is not null or empty. String s2 is null or empty. String s3 is null or empty. */
// This example demonstrates the String.IsNullOrEmpty() method import System.*; class Sample { public static void main(String[] args) { String s1 = "abcd"; String s2 = ""; String s3 = null; Console.WriteLine("String s1 {0}.", Test(s1)); Console.WriteLine("String s2 {0}.", Test(s2)); Console.WriteLine("String s3 {0}.", Test(s3)); } //main public static String Test(String s) { if (String.IsNullOrEmpty(s) == true) { return "is null or empty"; } else { return String.Format("(\"{0}\") is not null or empty", s); } } //Test } //Sample /* This example produces the following results: String s1 ("abcd") is not null or empty. String s2 is null or empty. String s3 is null or empty. */

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からString.IsNullOrEmpty メソッドを検索する場合は、下記のリンクをクリックしてください。

- String.IsNullOrEmpty メソッドのページへのリンク