Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove " " from java string

I have a java string with " " from a text file the program accesses with a Buffered Reader object. I have tried string.replaceAll(" ","") and it doesn't seem to work.

Any ideas?

cleaned = cleaned.replace(" "," ");
like image 524
Greg Avatar asked Jul 23 '10 13:07

Greg


4 Answers

cleaned = cleaned.replace("\u00a0","")
like image 160
Nitin Phadnis Avatar answered Nov 18 '22 23:11

Nitin Phadnis


This is a two step process:

strLineApp = strLineApp.replaceAll("&"+"nbsp;", " "); 
strLineApp = strLineApp.replaceAll(String.valueOf((char) 160), " ");

This worked for me. Hope it helps you too!

like image 36
Deep Sehgal Avatar answered Nov 18 '22 22:11

Deep Sehgal


The same way you mentioned:

String cleaned = s.replace(" "," ");

It works for me.

like image 8
Manuel Selva Avatar answered Nov 18 '22 21:11

Manuel Selva


There's a ready solution to unescape HTML from Apache commons:

StringEscapeUtils.unescapeHtml("")

You can also escape HTML if you want:

StringEscapeUtils.escapeHtml("")
like image 3
RichardK Avatar answered Nov 18 '22 21:11

RichardK