|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Replace "\" with "/" in Java
Can anybody please help me in replacing the "\" value as "/".
eg: str1\str2\str3 should get as str1/str2/str3 Please explain with a sample code Thanking You in advance |
|
#2
|
||||
|
||||
|
Try the replace method of the String class.
The following is off the top of my head, and untested. Code:
String tmp = new String("str1\\str2\\str3");
tmp = tmp.replace('\\', '/');
It's fairly straightforward and needs no explanation. |
|
#3
|
|||
|
|||
|
Quote:
Hi! I am new member and I think you have solved that problem now!it's 2 years over now ! I sent it for others!everyone can try like this!Code:
public static String backlashReplace(String myStr){
final StringBuilder result = new StringBuilder();
final StringCharacterIterator iterator = new StringCharacterIterator(myStr);
char character = iterator.current();
while (character != CharacterIterator.DONE ){
if (character == '\\') {
result.append("/");
}
else {
result.append(character);
}
character = iterator.next();
}
return result.toString();
}
Last edited by MadCowDzz : September 24th, 2007 at 01:20 PM. Reason: added [code] tags |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Replace "\" with "/" in Java |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|