|
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
|
Tradução
Original
|
Método String.IndexOf (String, Int32, Int32)
Assembly: mscorlib (em mscorlib.dll)
Parâmetros
- value
- Tipo: System.String
A seqüência de busca.
- startIndex
- Tipo: System.Int32
A posição inicial de pesquisa.
- count
- Tipo: System.Int32
O número de posições de caractere para examinar.
Valor de retorno
Tipo: System.Int32| Exceção | Condição |
|---|---|
| ArgumentNullException | |
| ArgumentOutOfRangeException |
// Sample for String.IndexOf(String, Int32, Int32) using System; class Sample { public static void Main() { string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"; string br2 = "0123456789012345678901234567890123456789012345678901234567890123456"; string str = "Now is the time for all good men to come to the aid of their party."; int start; int at; int end; int count; end = str.Length; start = end/2; Console.WriteLine(); Console.WriteLine("All occurrences of 'he' from position {0} to {1}.", start, end-1); Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str); Console.Write("The string 'he' occurs at position(s): "); count = 0; at = 0; while((start <= end) && (at > -1)) { // start+count must be a position within -str-. count = end - start; at = str.IndexOf("he", start, count); if (at == -1) break; Console.Write("{0} ", at); start = at+1; } Console.WriteLine(); } } /* This example produces the following results: All occurrences of 'he' from position 33 to 66. 0----+----1----+----2----+----3----+----4----+----5----+----6----+- 0123456789012345678901234567890123456789012345678901234567890123456 Now is the time for all good men to come to the aid of their party. The string 'he' occurs at position(s): 45 56 */
Windows 7, Windows Vista SP1 ou posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core não compatível), Windows Server 2008 R2 (Server Core não compatível com SP1 ou posterior), Windows Server 2003 SP2
O .NET Framework não oferece suporte a todas as versões de cada plataforma. Para obter uma lista das versões com suporte, consulte Requisitos de sistema do .NET Framework.