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?
1 Answer 1
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
Tim Biegeleisen
526k32 gold badges324 silver badges399 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Andreas
Why
\\b? Seems unnecessary.lang-java
sqrt()?