String.IsNullOrEmpty メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > String.IsNullOrEmpty メソッドの意味・解説 

String.IsNullOrEmpty メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定されString オブジェクトnull 参照 (Visual Basic では Nothing) または Empty 文字列であるかどうか示します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

IsNullOrEmpty メソッド使用すると、Stringnull 参照 (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.

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からString.IsNullOrEmpty メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からString.IsNullOrEmpty メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からString.IsNullOrEmpty メソッドを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「String.IsNullOrEmpty メソッド」の関連用語

String.IsNullOrEmpty メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



String.IsNullOrEmpty メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS