aspose file tools*
The moose likes Beginning Java and the fly likes how to replace colon (:) in a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to replace colon (:) in a String" Watch "how to replace colon (:) in a String" New topic
Author

how to replace colon (:) in a String

Kool dada
Greenhorn

Joined: Aug 30, 2007
Posts: 1
Hi Team,

I have a requirement like replace the colon ( in a string.
I tried with the following code:
/**
String str = "abc ef:ghi";
str.replaceAll(":","_");
system.out.println(str);
**/
But the output i am getting the string with unchanged.

output
----------
abc ef:ghi

Could you please let me know why i am not able to replace the colon?
Also point me to the correct code that satisfy my requirement.

Thanks.
Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
Hi

You wrote:
-------------------------------------------------------------

Hi Team,

I have a requirement like replace the colon ( in a string.
I tried with the following code:
/**
String str = "abc ef:ghi";
str.replaceAll(":","_");
system.out.println(str);
**/
But the output i am getting the string with unchanged.

output
----------
abc ef:ghi

Could you please let me know why i am not able to replace the colon?
Also point me to the correct code that satisfy my requirement.

Thanks.

---------------------------------------------------------------

the replaceAll method will return a String which is not assigned to any variable. Because of this you are not seeing the change. Replace your code

str.replaceAll(":","_");

with

str = str.replaceAll(":","_");

This will work.


~ Anand,
SCJP 1.5
SCWCD 1.5
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1344
    
  12
"Kool Dada",

Please check your private messages for an important message from me.

Kind regards,
Katrina Owen
Saloon Bartender
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to replace colon (:) in a String
 
Similar Threads
Replace all "." in a string
String Replace
equals() and ==, doubt
String input with parenthesis
how to compare a string using String tokenizer