Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-08-2011, 08:31 PM   PM User | #1
skytbest
New to the CF scene

 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
skytbest is an unknown quantity at this point
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
skytbest is offline   Reply With Quote
Old 12-09-2011, 02:13 AM   PM User | #2
Apothem
Regular Coder

 
Apothem's Avatar
 
Join Date: Mar 2008
Posts: 380
Thanks: 36
Thanked 25 Times in 25 Posts
Apothem is an unknown quantity at this point
I am not sure, but have you tried \\\\?
Apothem is offline   Reply With Quote
Old 12-11-2011, 01:28 AM   PM User | #3
renegadeandy
Regular Coder

 
Join Date: Feb 2008
Location: Edinburgh - Scotland
Posts: 107
Thanks: 0
Thanked 12 Times in 12 Posts
renegadeandy is an unknown quantity at this point
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);
	
	}
	

}
renegadeandy is offline   Reply With Quote
Reply

Bookmarks

Tags
backslash, forwardslash, slash, string

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:35 AM.


Advertisement
Log in to turn off these ads.