首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

不区分大小写查寻字符串(二)

2012-10-09 
不区分大小写查找字符串(二)public class StringUtil {public static void main(String[] args) {String t

不区分大小写查找字符串(二)
public class StringUtil {public static void main(String[] args) {String t="aaaaaaaaaa<table></table>aaa<table></table>";String s="<TABLE";//t="";System.out.println("length="+t.length());System.out.println(t.indexOf(s,0));System.out.println(ignoreIndexOf(t, s,0));System.out.println(t.lastIndexOf(s));System.out.println(ignoreLastIndexOf(t, s));}public static int ignoreIndexOf(String subject,String search){return ignoreIndexOf(subject,search,0);}public static int ignoreIndexOf(String subject,String search,int soffset){//当被查找字符串或查找子字符串为空时,抛出空指针异常。if (subject == null || search == null) {throw new NullPointerException("输入的参数为空");}if(soffset>=subject.length() && search.equals("")){return subject.length();}for (int i = soffset; i < subject.length(); i++) {if(subject.regionMatches(true, i, search, 0, search.length())){return i;}}return -1;}public static int ignoreLastIndexOf(String subject,String search) {return ignoreLastIndexOf(subject, search, subject.length());}public static int ignoreLastIndexOf(String subject,String search,int soffset) {//当被查找字符串或查找子字符串为空时,抛出空指针异常。if (subject == null || search == null) {throw new NullPointerException("输入的参数为空");}if(soffset<=0 && search.equals("")){return 0;}for (int i = soffset; 0 < i; i--) {if(subject.regionMatches(true, i, search, 0, search.length())){return i;}}return -1;}

热点排行