C# String LastIndexOfAny()
C# String LastIndexOfAny()
C#LastIndexOfAny() 方法用于查找此字符串中指定的一个或多个字符最后一次出现的索引位置。
签名
public int LastIndexOfAny(Char[] ch)
public int LastIndexOfAny(Char[], Int32)
public int LastIndexOfAny(Char[], Int32, Int32)
参数
ch:是字符类型数组。
返回
它返回整数值。
C# String LastIndexOfAny() 方法示例
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "abracadabra";
char[] ch = {'r','b'};
int index = s1.LastIndexOfAny(ch);//Finds 'r' at the last
Console.WriteLine(index);
}
}
输出:
C# String LastIndexOfAny() 方法示例 2
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "abracadabra";
char[] ch = {'t','b'};
int index = s1.LastIndexOfAny(ch);//Finds 'b' at the last
Console.WriteLine(index);
}
}
输出: