问题
I am new to java but not programming in general. I've been trying to understand Java String replaceAll...specifically I am reading in Strings from a text file...an example would be "I JUMP UP HIGH IN THE AIR TO GET TO YOU."
1) I want to change "I" to "A" where I is not the beginning of a word, and 2) U to "O" where U is at the end of a word. Any help would be appreciated. (Also, if you can point me to a good tutorial on the topic [I learn best by looking at examples] that would be appreciated)
回答1:
Try this.
String s = "I JUMP UP HIGH IN THE AIR TO GET TO YOU.";
s = s.replaceAll("(?!\\b)I", "A")
.replaceAll("U\\b", "O");
System.out.println(s);
// -> I JUMP UP HAGH IN THE AAR TO GET TO YOO.
来源:https://stackoverflow.com/questions/35835596/java-string-manipulation-replaceall