Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-02-2007, 06:07 PM
Member
 
Join Date: Jul 2007
Posts: 33
cecily is on a distinguished road
problems with replace method
I have this string:
Code:
String url="C:\file\test.txt";
and I want to write '/' instead of '\'
like this
Code:
url="C:/file/test.txt";
I've tried to use the replace but It didn't work

Code:
String url="C:\file\test.txt"; System.out.println(url.replace('\\','/'));
please help me
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-02-2007, 10:11 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,146
hardwired is on a distinguished road
Backslashes in java are escape tokens. To use them as character literals they need to be preceded by a backslash, ie, escaped. So if you want '\' to appear you have to write it as '\\'.
Code:
String escapedLetters = "C:\file\test.txt"; System.out.println("escapedLetters = " + escapedLetters); String url = "C:\\file\\test.txt"; System.out.println("url = " + url); String converted = url.replace('\\','/'); System.out.println("converted = " + converted);
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a replace method... paul New To Java 2 08-07-2007 05:50 AM
problems to find the main method christina Eclipse 2 08-06-2007 08:51 PM
String replace method venkata.tarigopula Advanced Java 1 07-10-2007 09:14 PM
Problems with method ai_2007 Advanced Java 1 06-28-2007 07:49 PM
Problems with Find method in EJB Nick15 Enterprise JavaBeans 0 05-14-2007 02:29 PM


All times are GMT +3. The time now is 09:36 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org