replacing non number-character characters from string

  • Thread starter Thread starter buu
  • Start date Start date
B

buu

How could I replace all characters from string wich are not characters,
numbers or some punctuation?

note that I would not like to use any kind of loops
is there any simple way?
 
buu said:
How could I replace all characters from string wich are not characters,
numbers or some punctuation?

note that I would not like to use any kind of loops
is there any simple way?

Well, whatever you do is going to involve a loop *somewhere*. It might
not be a loop in your code, but it'll be a loop somewhere. What do you
have against loops? If a loop is the simplest way of doing it, why not
use that?

(I suspect a regex replacement is actually the simplest here, but I
always get intrigued by people wanting to avoid a particular solution.)
 
buu said:
you're right...

but...just asking...
why use regex instead of string?

Because regex allows you to specify a pattern and say "replace
everything matching <this> pattern with <this> character". String
doesn't let you do that - you'd need looping (or a lot of very
repetitive code).
 
Back
Top