Remove white spaces from the Java string [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
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+","")

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

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",""));

Replace all √num from a string java [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
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)?

How do I find all substrings within two common characters in a given 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 6 years ago.
Improve this question
What I have:
String result = "<>hello<!><>Soumik<!><>Having a wonderful day?<!>";
What I need:
resultStrings = ["hello", "Soumik", "Having a wonderful day?"];
This regex should do the trick:
<[^>]*>([^<]+)<
Find all matches, and extract capturing group 1 from each.
Regex demo
How about that:
result = result.replace("<", "");
result = result.replace(">","";
resultStrings = result.split("!");
It's really simple.
I don't know other conditions so it may not be useful. Please add conditions so I can respond to it.

Insert comma to a string of numbers after specific numbers of digits [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 9 years ago.
Improve this question
I have this number
6430134080234080234080200000000
and i want it in this form :
643,01,340802,340802,340802,00000000
My aim is to insert it to a database.
First off, you obviously don't have a number, but a string.
String s = "6430134080234080234080200000000";
You can format it like so:
String formatted = s.substring(0,3) + "," + s.substring(3,5) + "," ...
Note that this only works if the input string is of the same length.

Categories