0

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"

ohadinho
  • 6,894
  • 16
  • 71
  • 124
  • http://stackoverflow.com/a/2220476/846476 will get you the unicode value. You can do a replace all for \d to find the numbers – RNJ Sep 14 '12 at 08:01
  • [You seem to like regexps and numbers...](http://stackoverflow.com/q/12419998/1225328) – sp00m Sep 14 '12 at 08:01

2 Answers2

1

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
Keppil
  • 45,603
  • 8
  • 97
  • 119
0

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.

Juvanis
  • 25,802
  • 5
  • 69
  • 87