• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about replace(',','')

 
nick wall
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic