How to remove “ ” from java string

后端 未结 9 1544
遥遥无期
遥遥无期 2020-12-17 07:31

I have a java string with \" \" from a text file the program accesses with a Buffered Reader object. I have tried string.replaceAll(\" 

相关标签:
9条回答
  • 2020-12-17 08:06

    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!

    0 讨论(0)
  • 2020-12-17 08:13

    I encountered the same problem: The inner HTML of the element I needed had "&nbsp" and my assertion failed. Since the question has not accepted any answer,yet I would suggest the following, which worked for me

    String string = stringwithNbsp.replaceAll("\n", "");
    

    P.S : Happy testing :)

    0 讨论(0)
  • 2020-12-17 08:14

    Strings are immutable so You need to do

    string = string.replaceAll(" ","")
    
    0 讨论(0)
  • 2020-12-17 08:15
    cleaned = cleaned.replace("\u00a0","")
    
    0 讨论(0)
  • 2020-12-17 08:16

    You can use JSoup library:

    String date = doc.body().getElementsByClass("Datum").html().toString().replaceAll(" ","").trim();
    
    0 讨论(0)
  • 2020-12-17 08:19

    Strings in Java are immutable. You have to do:

    String newStr = cleaned.replaceAll(" ", "");
    
    0 讨论(0)
提交回复
热议问题