1、 IndexOf
Study("全部匹配");
public static void Study(string b){
string[] a=new string[]{"匹配","一样"};
for(int i=0;i<a.Length;i++){
if(b.IndexOf(a[i],2,2)>=0){
string c=a[i];
Report.Info(c);
}
}
}
2、 LastIndexOf
Study("全部匹配字符串匹配");
public static void Study(string b){
string[] a=new string[]{"匹配","一样"};
for(int i=0;i<a.Length;i++){
string c=b.LastIndexOf(a[i]).ToString(); //输出字符最后匹配初始位置
string d=b.LastIndexOf(a[i],6).ToString();
if(Convert.ToInt32(c)>0||Convert.ToInt32(d)>0){
Report.Info("输出c :"+c);
Report.Info("输出d :"+d);
}
}
}
结果:
3、Substring
Study("全部匹配字符串匹配");
public static void Study(string b){
string c=b.Substring(5);
string d=b.Substring(3,5);
Report.Info("输出c :"+c);
Report.Info("输出d :"+d);
}
结果:
4、IndexOfAny
Study("sfgagv");
public static void Study(string b){
char[] a=new char[]{'a','c','t'};
if(b.IndexOfAny(a,2,2)>=0){
string c=Convert.ToString(b.IndexOfAny(a,2,2));
Report.Info(c);
}
}
结果: