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"

2

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.