String str="查找的字符串的位置"; String lookStr="字符串"; int i=str.indexOf(lookStr); 再用substring()就行了
用我上面写的语句Pattern.compile(reg).matcher(str) 就可以了但是现在遇到一个问题,如果字符串有乱码,如果才能把所有字符都取得,包括乱码 比如字符串中有:/Umeå FC - Landskrona Bois/test正则:/[^/]/但,不能全取
public class FindCharacters{ public static void main(String[] args){ String text="原字符串中可能含有很多符合条件的字符串,使用什么办法取得呢?"; int index=-1; String str1="字符串"; String str2=null;
}
String temp = str.substring(i,i+3)
......
}
for(int i =0 ;i<str.length-3;i+=1){
String temp = str.substring(i,i+findstr.length());if(temp.epuals(findstr){
.......
}
}
String lookStr="字符串";
int i=str.indexOf(lookStr);
再用substring()就行了
就可以了但是现在遇到一个问题,如果字符串有乱码,如果才能把所有字符都取得,包括乱码
比如字符串中有:/Umeå FC - Landskrona Bois/test正则:/[^/]/但,不能全取
public static void main(String[] args){
String text="原字符串中可能含有很多符合条件的字符串,使用什么办法取得呢?";
int index=-1;
String str1="字符串";
String str2=null;
index=text.indexOf(str1); while(index>=0){
str2=text.substring(index,(index+str1.length()));
System.out.println(str2);
index+=str1.length();
index=text.indexOf(str1,index);
}
}
}