0

I have a string that contains String q = "What's the value of √32 and √83?";, my problem is replacing √num with sqrt(32) and sqrt(83).

That means my string should output : -

What's the value of sqrt(32) and sqrt(83)

is it possible?

asked Oct 16, 2020 at 6:25
2
  • Are you trying to replace it programatically? like find every sqrt symble and replace it with sqrt()? Commented Oct 16, 2020 at 6:27
  • 1
    Does this answer your question? Java String.replace/replaceAll not working Commented Oct 16, 2020 at 22:44

1 Answer 1

5

Use a regex replacement on the pattern √(\d+)\b, and replace with sqrt(...):

String q = "What's the value of √32 and √83?";
String output = q.replaceAll("√(\\d+)\\b", "sqrt(1ドル)");
System.out.println(output);

This prints:

What's the value of sqrt(32) and sqrt(83)?
answered Oct 16, 2020 at 6:30
Sign up to request clarification or add additional context in comments.

1 Comment

Why \\b? Seems unnecessary.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.