자바에서 tr /// (Perl에서 사용 된 것과 동일)가 있는지 알고 싶습니다. 예를 들어, 내가 원한다면 모든 "의"S "미시시피"의 "P"의 반대와 교체, 나는, 펄, 나는 그것을 수행하는 생각할 수거기에 자바에서 tr /// (또는 동급)을 사용하는 방법은 무엇입니까?
#shebang and pragmas snipped...
my $str = "mississippi";
$str =~ tr/sp/ps/; # $str = "mippippissi"
print $str;
유일한 방법을 쓸 수있다 자바
String str = "mississippi";
str = str.replace('s', '#'); // # is just a dummy character to make sure
// any original 's' doesn't get switched to a 'p'
// and back to an 's' with the next line of code
// str = "mi##i##ippi"
str = str.replace('p', 's'); // str = "mi##i##issi"
str = str.replace('#', 'p'); // str = "mippippissi"
System.out.println(str);
이 할 수있는 더 나은 방법이 있는가 즉, String.replace()
방법 더미 문자를 사용할 수 있나요?
미리 감사드립니다.
http://stackoverflow.com/questions/ 3254358/replace-char-to-char-in-a-string –