C# String LastIndexOfAny(Char[], Int32, Int32)

Description

String LastIndexOfAny(Char[], Int32, Int32) reports the zero-based index position of the last occurrence in this instance of one or more characters specified in a Unicode array. The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions.

Syntax

String.LastIndexOfAny(Char[], Int32, Int32) has the following syntax.


public int LastIndexOfAny(
  char[] anyOf,//  ww  w  .j  a v  a  2s.c  om
  int startIndex,
  int count
)

Parameters

String.LastIndexOfAny(Char[], Int32, Int32) has the following parameters.

  • anyOf - A Unicode character array containing one or more characters to seek.
  • startIndex - The search starting position. The search proceeds from startIndex toward the beginning of this instance.
  • count - The number of character positions to examine.

Returns

String.LastIndexOfAny(Char[], Int32, Int32) method returns The index position of the last occurrence in this instance where any character in anyOf was found; -1 if no character in anyOf was found or if the current instance equals String.Empty.

Example

Sample for String.LastIndexOfAny(Char[], Int32, Int32)


/*w  ww.  j a v  a  2 s .c o m*/
using System;

class Sample {
    public static void Main() {
    string str = "this is a test.";
    string target = "is";
    char[] anyOf = target.ToCharArray();
    int start = ((str.Length-1)*2)/3;
    int count = (str.Length-1)/3;

    int at = str.LastIndexOfAny(anyOf, start, count);
    if (at > -1) 
        Console.Write(at);
    else
        Console.Write("(not found)");
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version