...

View Full Version : change all "\" to "/"



skytbest
12-08-2011, 08:31 PM
I'm looking for a simple piece of code that will change all the backslashes in a string to forward slashes.

I tried this:
word.replaceAll("\\","/");

but it will not work. Anyone have a quick fix for this?

Thanks

Apothem
12-09-2011, 02:13 AM
I am not sure, but have you tried \\\\?

renegadeandy
12-11-2011, 01:28 AM
Why would you want to do that, is this for path conversion or something?

Anyhow - tried what Apothem suggested and it works:



public class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

String testStr = "hello\\this\\is\\fun";
String newStr = testStr.replaceAll("\\\\", "/");
System.out.println(newStr);

}


}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum