C# String LastIndexOfAny(Char[])

Description

String LastIndexOfAny(Char[]) reports the zero-based index position of the last occurrence in this instance of one or more characters specified in a Unicode array.

Syntax

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


public int LastIndexOfAny(
  char[] anyOf
)

Parameters

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

  • anyOf - A Unicode character array containing one or more characters to seek.

Returns

String.LastIndexOfAny(Char[]) 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.

Example

Sample for String.LastIndexOfAny(Char[])


/*  w  w w.j a v  a  2s. co  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;
        int at = str.LastIndexOfAny(anyOf);
        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