• Post Reply Bookmark Topic Watch Topic
  • New Topic

Removing dahes out of string  RSS feed

 
john mccain
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys. first post. im stuck and i cant figure out how to remove dashes out of an input string that MAY or MAY NOT have dashes. Would i be looking to use char or what? Also another thing is im trying to not use arrays.

Here is my method header:

Would love some help please.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at String's replaceAll() method.
 
john mccain
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelle Klap wrote:Have a look at String's replaceAll() method.


Alright i looked at that and i got this far...

Now what would i put in the XXX to make it remove it completely?

OR how do i use replaceAll for this situation? i need to completely get rid of dashes for an isbn method.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That compiles?!

In any case: what do you want to replace it with? Nothing, right? So... what's string-ese for nothing?
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's this "char 45" stuff, anyway?

Note that in the API the Jelle linked to, there's a replace() method, and a replaceAll(). Pay attention to the difference.

Good to see you're keeping busy after the election, sir. Good luck.
 
john mccain
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OKAY OKAY. semi success. My code now:


So now it works but i need to make it to work weather it has or doesnt have dashes. Any help while i try stuff?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seeing as how there's no "remove()" method, consider replacing. Again--with what? Your answer should be "nothing". Again--what's String-eze for nothing?
 
john mccain
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Seeing as how there's no "remove()" method, consider replacing. Again--with what? Your answer should be "nothing". Again--what's String-eze for nothing?


its "". lol i got that. i am now making a if-else statement to test if it has dashes, remove dashes. else do nothing....
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why bother? Wouldn't anything doing any replacing have to check anyway?
 
john mccain
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh hold on.. lemme try something i mighta missed :P
 
john mccain
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah i got it!! thanks alot guys. ill be sure to stick around this forum.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!