C# LastIndexOfAny() 方法用于查找此字符串中指定的一个或多个字符的最后一次出现的索引位置。
public int LastIndexOfAny(Char[] ch) public int LastIndexOfAny(Char[], Int32) public int LastIndexOfAny(Char[], Int32, Int32)
ch:字符型数组。
它返回整数值。
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); } }
输出:
9
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); } }
输出:
8