CharEnumerator.MoveNext CharEnumerator.MoveNext CharEnumerator.MoveNext CharEnumerator.MoveNext Method

Definition

Inkrementiert den internen Index des aktuellen CharEnumerator-Objekts zum nächsten Zeichen der aufgelisteten Zeichenfolge.Increments the internal index of the current CharEnumerator object to the next character of the enumerated string.

public:
 virtual bool MoveNext();
public bool MoveNext ();
abstract member MoveNext : unit -> bool
override this.MoveNext : unit -> bool
Public Function MoveNext () As Boolean

Gibt zurück

true, wenn der Index erhöht werden konnte und sich innerhalb der aufgelisteten Zeichenfolge befindet, andernfalls false.true if the index is successfully incremented and within the enumerated string; otherwise, false.

Implementiert

Beispiele

Im folgenden Beispiel wird die CharEnumerator Klasse, um die einzelnen Zeichen in einer Zeichenfolge aufgelistet werden.The following example uses the CharEnumerator class to enumerate the individual characters in a string. Es instanziiert ein CharEnumerator -Objekt durch Aufrufen der String.GetEnumerator -Methode von einem Zeichen zum nächsten wechselt durch Aufrufen der MoveNext -Methode, und zeigt das aktuelle Zeichen durch Abrufen des Werts von der Current Eigenschaft.It instantiates a CharEnumerator object by calling the String.GetEnumerator method, moves from one character to the next by calling the MoveNext method, and displays the current character by retrieving the value of the Current property.

String ^ title = "A Tale of Two Cities";
CharEnumerator ^ chEnum = title->GetEnumerator();
int ctr = 1;
String ^ outputLine1 = nullptr;
String ^ outputLine2 = nullptr;
String ^ outputLine3 = nullptr; 

while (chEnum->MoveNext())
{
   outputLine1 += ctr < 10 || ctr % 10 != 0 ? "  " : (ctr / 10) + " ";
   outputLine2 += (ctr % 10) + " ";
   outputLine3 += chEnum->Current + " ";
   ctr++;
}

Console::WriteLine("The length of the string is {0} characters:", 
                  title->Length);
Console::WriteLine(outputLine1);
Console::WriteLine(outputLine2);    
Console::WriteLine(outputLine3);
// The example displays the following output to the console:      
//       The length of the string is 20 characters:
//                         1                   2
//       1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
//       A   T a l e   o f   T w o   C i t i e s
string title = "A Tale of Two Cities";
CharEnumerator chEnum = title.GetEnumerator();
int ctr = 1;
string outputLine1 = null;
string outputLine2 = null;
string outputLine3 = null; 

while (chEnum.MoveNext())
{
   outputLine1 += ctr < 10 || ctr % 10 != 0 ? "  " : (ctr / 10) + " ";
   outputLine2 += (ctr % 10) + " ";
   outputLine3 += chEnum.Current + " ";
   ctr++;
}

Console.WriteLine("The length of the string is {0} characters:", 
                  title.Length);
Console.WriteLine(outputLine1);
Console.WriteLine(outputLine2);    
Console.WriteLine(outputLine3);
// The example displays the following output to the console:      
//       The length of the string is 20 characters:
//                         1                   2
//       1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
//       A   T a l e   o f   T w o   C i t i e s
Dim title As String = "A Tale of Two Cities"
Dim chEnum As CharEnumerator = title.GetEnumerator()
Dim ctr As Integer = 1
Dim outputLine1, outputLine2, outputLine3 As String 

Do While chEnum.MoveNext()
   outputLine1 += CStr(iif(ctr < 10 Or ctr Mod 10 <> 0, "  ", CStr(ctr \ 10) + " ")) 
   outputLine2 += (ctr Mod 10)& " "
   outputLine3 += chEnum.Current & " "
   ctr += 1
Loop

Console.WriteLine("The length of the string is {0} characters:", _
                  title.Length)
Console.WriteLine(outputLine1)
Console.WriteLine(outputLine2)    
Console.WriteLine(outputLine3)
' The example displays the following output to the console:      
'       The length of the string is 20 characters:
'                         1                   2
'       1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
'       A   T a l e   o f   T w o   C i t i e s

Beachten Sie jedoch, dass es sich bei der gleiche Vorgang mithilfe intuitiver ausgeführt werden kann foreach (in c#) oder For Each (in Visual Basic), wie im folgenden Beispiel gezeigt.Note, however, that the same operation can be performed somewhat more intuitively by using foreach (in C#) or For Each (in Visual Basic), as the following example shows.

String ^ title = "A Tale of Two Cities";
int ctr = 1;
String ^ outputLine1 = nullptr;
String ^ outputLine2 = nullptr;
String ^ outputLine3 = nullptr; 

for each (wchar_t ch in title)
{
   outputLine1 += ctr < 10 || ctr % 10 != 0 ? "  " : (ctr / 10) + " ";
   outputLine2 += (ctr % 10) + " ";
   outputLine3 += ch + " ";
   ctr++;
}

Console::WriteLine("The length of the string is {0} characters:", 
                  title->Length);
Console::WriteLine(outputLine1);
Console::WriteLine(outputLine2);    
Console::WriteLine(outputLine3);
// The example displays the following output to the console:      
//       The length of the string is 20 characters:
//                         1                   2
//       1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
//       A   T a l e   o f   T w o   C i t i e s
string title = "A Tale of Two Cities";
int ctr = 1;
string outputLine1 = null;
string outputLine2 = null;
string outputLine3 = null; 

foreach (char ch in title)
{
   outputLine1 += ctr < 10 || ctr % 10 != 0 ? "  " : (ctr / 10) + " ";
   outputLine2 += (ctr % 10) + " ";
   outputLine3 += ch + " ";
   ctr++;
}

Console.WriteLine("The length of the string is {0} characters:", 
                  title.Length);
Console.WriteLine(outputLine1);
Console.WriteLine(outputLine2);    
Console.WriteLine(outputLine3);
// The example displays the following output to the console:      
//       The length of the string is 20 characters:
//                         1                   2
//       1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
//       A   T a l e   o f   T w o   C i t i e s
Dim title As String = "A Tale of Two Cities"
Dim ctr As Integer = 1
Dim outputLine1, outputLine2, outputLine3 As String 

For Each ch As Char In title
   outputLine1 += CStr(iif(ctr < 10 Or ctr Mod 10 <> 0, "  ", CStr(ctr \ 10) + " ")) 
   outputLine2 += (ctr Mod 10)& " "
   outputLine3 += ch & " "
   ctr += 1
Next

Console.WriteLine("The length of the string is {0} characters:", _
                  title.Length)
Console.WriteLine(outputLine1)
Console.WriteLine(outputLine2)    
Console.WriteLine(outputLine3)
' The example displays the following output to the console:      
'       The length of the string is 20 characters:
'                         1                   2
'       1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
'       A   T a l e   o f   T w o   C i t i e s

Hinweise

Die CharEnumerator Klasse verwaltet einen internen Index der aufgelisteten Zeichenfolge ein, und die MoveNext -Methode erhöht den Index um eins.The CharEnumerator class maintains an internal index to the enumerated string, and the MoveNext method increments the index by one. Rufen Sie MoveNext nach dem Aufruf GetEnumerator oder Reset erhöht die aktuellen Zeichenposition auf das erste Zeichen der aufgelisteten Zeichenfolge.Call MoveNext after calling GetEnumerator or Reset to increment the current character position to the first character in the enumerated string. Überprüfen Sie, ob der Rückgabewert true ermitteln, ob die aktuelle Zeichenposition gültig ist.Check that the return value is true to determine that the current character position is valid.

Wenn der Index bereits hinter dem letzten Zeichen der aufgelisteten Zeichenfolge ist, wird der Index wird nicht geändert und false zurückgegeben wird.If the index is already beyond the last character of the enumerated string, the index is not changed and false is returned.

Beachten Sie, dass, wenn die aufgelistete Zeichenfolge leer ist (""), wird der Status der CharEnumerator ist immer ungültig.Notice that if the enumerated string is empty (""), the state of the CharEnumerator is always invalid. Grund hierfür ist, den internen Index für die CharEnumerator zunächst vor dem ersten Zeichen der aufgelisteten Zeichenfolge ist und daher ungültig.This is because the internal index for the CharEnumerator is initially before the first character of the enumerated string and is therefore invalid. MoveNext logisch legt den Index fest, nach dem letzten (nicht vorhandenen) Zeichen der aufgelisteten Zeichenfolge ist ungültig.MoveNext logically sets the index after the last (nonexistent) character of the enumerated string which is also invalid.

Gilt für: