내 콘솔 (아래 이미지)이 있고 newstring에 대한 모든 oldstinrg를 대체 할 명령이 있습니다. 그러나 얼마나 많은 사람들이 교체 되었는가?Java string.replace (old, new) 얼마나 많은 대체 된?
(
(코드 번만 그것이 한 것 후 B로하지만 대체 경우 두번 값이 2가 될 것이다 b에 교체 한 경우)이 코드의 단지 일부이며 하지만 다른 부분은 필요하지 않습니다 또는 어떻게 관련이 String.replaceFirst를 사용하고 스스로를 셀 수
else if(intext.startsWith("replace ")){
String[] replist = original.split(" +");
String repfrom = replist[1];
String repto = replist[2];
lastorep = repfrom;
lasttorep = repto;
String outtext = output.getText();
String newtext = outtext.replace(repfrom, repto);
output.setText(newtext);
int totalreplaced = 0; //how to get how many replaced strings were there?
message("Total replaced: " + totalreplaced + " from " + repfrom + " to " + repto);
}
(오래된 문자열)과 (새로운 캐릭터처럼
Matcher#appendReplacement
및Matcher#appendTail
방법을 사용할 수 있습니다 하나 개의 반복에서 계산 얻을) 대체 할 대상은 무엇입니까? 패턴 (구)과 교체 (신품)입니까, 아니면? – donemanuel괜찮아요. 당신의 예제가 더 이상 작동하도록 수정 해주세요. –
... 편집 ... 도움이 되었으면 좋겠어요. –