Replace all √num from a string java [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
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?

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)?

Related

ascii value as string to character in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a String value "\u0004"
I need to convert it to character '\u0004'
I need to store this character back to the string.
How can this be done?
Maybe this is answer you want
// string value that has "\" in front
String s = "\\u0004";
// substring to leave "\u" out
char c = (char)Integer.parseInt(s.substring(2));

Remove white spaces from the Java string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Am trying to remove the spaces from the java string leaving the special characters,...
existing: "[Cars]/Info/{​​​​​​​​​ 123}​​​​​​​​​ /{4533449​​​​​​​​​ }​ ";
expected: "[Cars]/Info/{​​​​​​​​​123}​​​​​​​​​/{4533449​​​​​​​​​}";
Any help would be really appreciated..
You should use .replace(toReplace, replaceWith) like so:
st.replaceAll("\\s+","")
Where st is "[Cars]/Info/{​​​​​​​​​ 123}​​​​​​​​​ /{4533449​​​​​​​​​ }​ "
This:
String st = "[Cars]/Info/{​​​​​​​​​ 123}​​​​​​​​​ /{4533449​​​​​​​​​ }​ ";
System.out.println(st.replaceAll("\\s+",""));
Produces this:
[Cars]/Info/{​​​​​​​​​123}​​​​​​​​​/{4533449​​​​​​​​​}​
If you want to remove the spaces for the specific variable, use
st = st.replaceAll("\\s+","")

How to take out the numbers from the String and eliminate those number and store the filtered String and print it in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
String txt = "d89%l++5r19o7W *o=1645le9H"
System.out.println(t.replace(/\\d{0,}/g,''));
Because i'm bored...
String txt = "d89%l++5r19o7W *o=1645le9H";
txt = txt.replaceAll("\\d", "")
System.out.println(txt);
This will all numerical charactors from string
System.out.println(string.replaceAll("\\d",""));

I want to convert the string to float [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to convert GBP 29.15* to just 29.15.
Can anyone please help?
I have already tried parsing to integer/float, substring etc. but getting an error.
Try this:
float f = Float.valueOf("GBP 29.15*".replaceAll("[^\\d.]+|\\.(?!\\d)", ""));
It removes all non-number characters and then finds the float value.
See also: How to get float value from string

How to parse String vars in Java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
What is the best way to parse a String value that looks like this id#1 ...id#398, so I can get de number after the id# String in JAVA.
If id# is a fixed prefix in every ID, I would have used
stringValue.split("id#")[0]

Categories