$ {N} for the parameters may not have more than one digital size of incremental other words: I play $ $ { 2} {1 } : Or: I play $ $ { 1} {3 } this format is possible with the guidance of God seeking large JAVA
------ Solution ----------------------- ---------------------
public static void main(String[] args) {
String str = "我和${1}去打${2} ";
str = str.replaceAll("\\$\\{(\\d+)\\}", "#p_$1#");
System.out.println(str);
}
------ Solution ------------- -------------------------------
public static void main(String[] args) {
String str = "我和#p_1#去打#p_2#";
str = str.replaceAll("#p_(\\d+)#", "\\$\\{$1\\}");
System.out.println(str);
}
------ For reference only ----------------------------------- ----
ashamed ah ! You suddenly I solved this still thinking how to replace the loop ! Hey ! If they have to replace Le example will turn me and me and # p_1 # play # p_2 #: Replace : I play $ $ { 1} {2 } < br>
没有评论:
发表评论