This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes question about replace(',','') Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "question about replace( Watch "question about replace( New topic

question about replace(',','')

nick wall

Joined: Aug 27, 2003
Posts: 5
I have searched this forum and found various solutions to my problem (involving looping over string etc.), but I am still a little confused about the replace method (This is actually with reference to page 295 of Head First Java).
I am trying to replace the commas in 1,234,567 with "blank spaces" to get 1234567. If I use:
myString.replace(',', '') I get an "empty character literal" compiler error. If I do: static char nullChar; myString.replace(',',nullChar); that places a space.
How does one assign a char myChar = "null character"?
Any comments greatly appreciated.
Joel McNary

Joined: Aug 20, 2001
Posts: 1817

I'm not sure that you can do it with the replace method, simply because there is not concept of the "empty character". You would probably want to do it with the replaceAll method, which replaces strings -- which does have the "empty string" concept.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
wood burning stoves
subject: question about replace(',','')
Similar Threads
Char Conversion
Replaceing Characters
Javascript RegExp expression
trim function in Javascript
How to replace apostophes?