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

String.Contains メソッド

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

指定した String オブジェクトがこの文字列内に存在するかどうかを示す値を返します

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

例外例外
例外種類条件

ArgumentNullException

valuenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

文章中に文字列 "fox" が出現するかどうか確認するコード例次に示します

' This example demonstrates the String.Contains() method
Imports System

Class Sample
   Public Shared Sub Main()
      Dim s1 As String =
 "The quick brown fox jumps over the lazy dog"
      Dim s2 As String =
 "fox"
      Dim b As Boolean
      b = s1.Contains(s2)
      Console.WriteLine("Is the string, s2, in the string, s1?:
 {0}", b)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'Is the string, s2, in the string, s1?: True
'
// This example demonstrates the String.Contains() method
using System;

class Sample 
{
    public static void Main()
 
    {
    string s1 = "The quick brown fox jumps over the lazy
 dog";
    string s2 = "fox";
    bool b;
    b = s1.Contains(s2);
    Console.WriteLine("Is the string, s2, in
 the string, s1?: {0}", b);
    }
}
/*
This example produces the following results:

Is the string, s2, in the string,
 s1?: True
*/
// This example demonstrates the String.Contains() method
using namespace System;
int main()
{
   String^ s1 = "The quick brown fox jumps over the lazy dog";
   String^ s2 = "fox";
   bool b;
   b = s1->Contains( s2 );
   Console::WriteLine( "Is the string, s2, in
 the string, s1?: {0}", b );
}

/*
This example produces the following results:

Is the string, s2, in the string,
 s1?: True
*/
// This example demonstrates the String.Contains() method
import System.*;

class Sample
{
    public static void main(String[]
 args)
    {
        String s1 = "The quick brown fox jumps over the lazy dog";
        String s2 = "fox";
        boolean b;
        b = s1.Contains(s2);
        Console.WriteLine("Is the string, s2, in
 the string, s1?: {0}", 
            (System.Boolean)b);
    } //main
} //Sample
/*
This example produces the following results:

Is the string, s2, in the string,
 s1?: True
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2025 GRAS Group, Inc.RSS