I have this sentence:
"I have 3 bananas at 20:00 o'clock".
I need to replace the number in the string so it will include unicode:
"I have \u200e3\u200e bananas at \u200e20\u200e:\u200e00\u200e o'clock"
I have this sentence:
"I have 3 bananas at 20:00 o'clock".
I need to replace the number in the string so it will include unicode:
"I have \u200e3\u200e bananas at \u200e20\u200e:\u200e00\u200e o'clock"
The replacement in your example can be done using String.replaceAll()
:
String string = "I have 3 bananas at 20:00 o'clock";
string = string.replaceAll("\\d+", "\\\\u200e$0\\\\u200e");
System.out.println(string);
prints
I have \u200e3\u200e bananas at \u200e20\u200e:\u200e00\u200e o'clock
Preparing a hashmap for digits can solve your problem. Make the numbers as the keys of hashmap whereas the values are the corresponding Unicode values. Then use replace()
invocations to replace the numbers with their values in the hashmap. I hope this methodology makes sense.