Java, Removing a backslash in a string object

I have a url like this: in a string object. http:\/\/www.example.com\/example

Can someone tell me how to remove backslash?

I program for a blackberry system.

+3
source share
4 answers

See String.replace (CharSequence, CharSequence)

String myUrl = "http:\\/\\/www.example.com\\/example";
myUrl = myUrl.replace("\\","");
+7
source

@ Kevin's answer contains a fatal problem. String.replace(char, char)replaces occurrences of one character with another character. It does not delete characters.

''Java is also invalid because there is no such thing as an empty character.

Here are some solutions that should really work (and compile!):

    String myUrl = "http:\\/\\/www.example.com\\/example";
    fixedUrl = myUrl.replace("\\", "");

.

    fixedUrl = myUrl.replace("\\/", "/");

.

    fixedUrl = myUrl.replaceAll("\\\\(.)", "\\1");

"" escape- String, escape- . , .

, replaceAll, match/replace, String match/replace. ; , , , , .


, - .

. Blackberry - J2ME, J2ME String (. javadoc) String.replace(char, char), ( ) . J2ME String StringBuffer StringBuffer.delete(...) StringBuffer.replace(...).

( , Android...)

+6

Try the following:

return myUrl.replaceAll("\\\\(.)", "\\/");
0
source

Only this works for me -

String url = "http:\/\/imgd2.aeplcdn.com\/310x174\/cw\/cars\/ford\/ford-figo-aspire.jpg";

    for(int i = 0; i < url.length(); i++)
        if(url.charAt(i) == '\\')
            url = url.substring(0, i) + url.substring(i + 1, url.length());
0
source

Source: https://habr.com/ru/post/1794415/


All Articles