import java.util.Enumeration;
import java.util.Hashtable;
public class BasicReplace {
public static void main(String[] args) {
Hashtable<String, Integer> values = new Hashtable<String, Integer>();
values.put("%J", 3);
values.put("%F", 5);
values.put("%E", 7);
String inputStr = "XYZ: %J ABC: %F";
String currentKey;
Enumeration<String> enume = values.keys();
while(enume.hasMoreElements()){
currentKey = enume.nextElement();
inputStr = inputStr.replaceAll(currentKey, String.valueOf(values.get(currentKey)));
}
System.out.println(inputStr);
System.out.println("XYZ: %J Num: %f".replace("%J", "12").replace("%f", "34"));
}
}
TUNDUN !: D
Well, this may not be exactly the “easy way”, but it works.
source
share