João Machete

Archive for August, 2009

Replace backslash character to slash in a String with JAVA

by admin on Aug.20, 2009, under General

Today I had a small problem with java, and I leave here my solution to help others who are in the same situation.

Here I give you a small trick to replace backslash special caracter to another caracter in Java. If you are doing some project, and you need to replace a backslash “\” with the forward slash “/”, you will notice you can´t do this in the normal way.

Let´s see “the normal way”:

String address = "C:\Program Files\Java\jre6"
address = address.replace("\" , "/"):

you will have a error.

try this….

String address = "C:\Program Files\Java\jre6"
String backslash= System.getProperty("file.separator") ;
address= address.replace(backslash,"/");
System.out.println(address);

OUTPUT:

C:/Program Files/Java/jre6

;)

inputPath = inputPath.replace(barra,”/”);
System.out.println(inputPath)
Leave a Comment : more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Archives

All entries, chronologically...