This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to replace colon (:) in a String

 
Kool dada
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Katrina Owen
Sheriff
Pie
Posts: 1367
18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic