Java 获取字符串中第N次出现的字符位置
(2012-04-06 10:50:27) 标签: string截取位置it | 分类: JAVA_Discuss |
public static int getCharacterPosition(String string){
//这里是获取"/"符号的位置
Matcher slashMatcher = Pattern.compile("/").matcher(string);
int mIdx = 0;
while(slashMatcher.find()) {
mIdx++;
//当"/"符号第三次出现的位置
if(mIdx == 3){
break;
}
}
return slashMatcher.start();
}
本文提供了一个Java方法,用于在给定的字符串中查找特定字符的第N次出现的位置。
3032

被折叠的 条评论
为什么被折叠?



