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

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

String.GetEnumerator メソッド

この文字列含まれる個々文字反復処理するオブジェクト取得します

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

Public Function GetEnumerator As
 CharEnumerator
Dim instance As String
Dim returnValue As CharEnumerator

returnValue = instance.GetEnumerator
public CharEnumerator GetEnumerator ()
public:
CharEnumerator^ GetEnumerator ()
public CharEnumerator GetEnumerator ()

戻り値
CharEnumerator オブジェクト

解説解説
使用例使用例

GetEnumerator メソッド使用して入力文字列の各 System.Char を表示するコード例次に示します

' Example for the String.GetEnumerator( ) method.
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic

Module GetEnumerator
   
    Sub Main()
        Console.WriteLine( _
            "This example of String.GetEnumerator( ) "
 & _
            "generates the following output.")

        EnumerateAndDisplay("Test Case")
        EnumerateAndDisplay("Has" & vbTab &
 "two" & vbTab & "tabs")
        EnumerateAndDisplay("Two" & vbLf &
 "new" & vbLf & "lines")
    End Sub 'Main
       
    Sub EnumerateAndDisplay(Operand As String)

        Console.WriteLine( _
            vbCrLf & "The characters in the string ""{0}""
 are:", Operand)
          
        Dim OperandEnum As IEnumerator = Operand.GetEnumerator()
        Dim CharCount As Integer
 = 0
          
        While OperandEnum.MoveNext()
            CharCount += 1
            Console.Write(" ""{0}""
 ", OperandEnum.Current)
        End While

        Console.WriteLine(vbCrLf & " Character count: {0}",
 CharCount)

    End Sub 'EnumerateAndDisplay
End Module 'GetEnumerator

' This example of String.GetEnumerator( ) generates the following output.
' 
' The characters in the string "Test Case" are:
'  "T"  "e"  "s"  "t"  "
 "  "C"  "a"  "s"  "e"
'  Character count: 9
' 
' The characters in the string "Has       two     tabs" are:
'  "H"  "a"  "s"  "       "
  "t"  "w"  "o"  "     "  "t"
  "a"  "b"  "s"
'  Character count: 12
' 
' The characters in the string "Two
' new
' lines" are:
'  "T"  "w"  "o"  "
' "  "n"  "e"  "w"  "
' "  "l"  "i"  "n"  "e"
  "s"
'  Character count: 13
// Example for the String.GetEnumerator( ) method.
using System;
using System.Collections;

class GetEnumerator 
{
    public static void Main()
 
    {
        Console.WriteLine( 
            "This example of String.GetEnumerator( ) " +
            "generates the following output." );

        EnumerateAndDisplay( "Test Case" );
        EnumerateAndDisplay( "Has\ttwo\ttabs" );
        EnumerateAndDisplay( "Two\nnew\nlines" );
    }

    static void EnumerateAndDisplay( String
 Operand )
    {
        Console.WriteLine( 
            "\nThe characters in the string
 \"{0}\" are:",
            Operand );

        IEnumerator OperandEnum = Operand.GetEnumerator( );
        int         CharCount = 0;

        while( OperandEnum.MoveNext( ) )
        {
            CharCount++;
            Console.Write( " '{0}' ", OperandEnum.Current );
        }
        Console.WriteLine( "\n Character count: {0}", CharCount );
    }
}

/*
This example of String.GetEnumerator( ) generates the following output.

The characters in the string "Test Case"
 are:
 'T'  'e'  's'  't'  ' '  'C'  'a'  's'  'e'
 Character count: 9

The characters in the string "Has    
   two     tabs" are:
 'H'  'a'  's'  '       '  't'  'w'  'o'  '     '  't'  'a'  'b'  's'
 Character count: 12

The characters in the string "Two
new
lines" are:
 'T'  'w'  'o'  '
'  'n'  'e'  'w'  '
'  'l'  'i'  'n'  'e'  's'
 Character count: 13
*/
// Example for the String::GetEnumerator( ) method.
using namespace System;
using namespace System::Collections;
void EnumerateAndDisplay( String^ Operand )
{
   Console::WriteLine( "\nThe characters in the string
 \"{0}\" are:", Operand );
   IEnumerator^ OperandEnum = Operand->GetEnumerator();
   int CharCount = 0;
   while ( OperandEnum->MoveNext() )
   {
      CharCount++;
      Console::Write( " '{0}' ", OperandEnum->Current );
   }

   Console::WriteLine( "\n Character count: {0}", CharCount );
}

int main()
{
   Console::WriteLine( "This example of String::GetEnumerator( ) "
   "generates the following output." );
   EnumerateAndDisplay( "Test Case" );
   EnumerateAndDisplay( "Has\ttwo\ttabs" );
   EnumerateAndDisplay( "Two\nnew\nlines" );
}

/*
This example of String::GetEnumerator( ) generates the following output.

The characters in the string "Test Case"
 are:
 'T'  'e'  's'  't'  ' '  'C'  'a'  's'  'e'
 Character count: 9

The characters in the string "Has    
   two     tabs" are:
 'H'  'a'  's'  '       '  't'  'w'  'o'  '     '  't'  'a'  'b'  's'
 Character count: 12

The characters in the string "Two
new
lines" are:
 'T'  'w'  'o'  '
'  'n'  'e'  'w'  '
'  'l'  'i'  'n'  'e'  's'
 Character count: 13
*/
// Example for the String.GetEnumerator( ) method.
import System.*;
import System.Collections.*;

class GetEnumerator
{
    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of String.GetEnumerator( ) "
            + "generates the following output."));
        EnumerateAndDisplay("Test Case");
        EnumerateAndDisplay("Has\ttwo\ttabs");
        EnumerateAndDisplay("Two\nnew\nlines");
    } //main

    static void EnumerateAndDisplay(String
 operand)
    {
        Console.WriteLine("\nThe characters in the string
 \"{0}\" are:", 
            operand);
        IEnumerator operandEnum = operand.GetEnumerator();
        int charCount = 0;
        while(operandEnum.MoveNext()) {
            charCount++;
            Console.Write(" '{0}' ", operandEnum.get_Current());
        }
        Console.WriteLine("\n Character count: {0}", 
            String.valueOf(charCount));
    } //EnumerateAndDisplay
} //GetEnumerator

/*
This example of String.GetEnumerator( ) generates the following output.

The characters in the string "Test Case"
 are:
 'T'  'e'  's'  't'  ' '  'C'  'a'  's'  'e'
 Character count: 9

The characters in the string "Has    
   two     tabs" are:
 'H'  'a'  's'  '       '  't'  'w'  'o'  '     '  't'  'a'  'b'  's'
 Character count: 12

The characters in the string "Two
new
lines" are:
 'T'  'w'  'o'  '
'  'n'  'e'  'w'  '
'  'l'  'i'  'n'  'e'  's'
 Character count: 13
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2025 GRAS Group, Inc.RSS