Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question change all "\" to "/"

    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

  • #2
    Regular Coder Apothem's Avatar
    Join Date
    Mar 2008
    Posts
    380
    Thanks
    36
    Thanked 25 Times in 25 Posts
    I am not sure, but have you tried \\\\?

  • #3
    Regular Coder
    Join Date
    Feb 2008
    Location
    Edinburgh - Scotland
    Posts
    107
    Thanks
    0
    Thanked 12 Times in 12 Posts
    Why would you want to do that, is this for path conversion or something?

    Anyhow - tried what Apothem suggested and it works:

    Code:
    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);
    	
    	}
    	
    
    }


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •