|
Pages: [1]
|
 |
|
Author
|
Topic: Removing characters (Read 308 times)
|
|
jmatro
|
How do I remove all letters (a-zA-Z) from a string?
For example, given "1abc2def14xyz9" I want to obtain "12149".
Given all the tools in REBOL, it should be easy, but I can't see it. Hope I'm not missing something obvious.
Thanks.
|
|
|
|
|
Logged
|
|
|
|
Guest_jmatro
Guest
|
Found one way to do it!!
string: "1abc2def14xyz9"
remove-each v string [find "abcdefghijklmnopqrstuvwxyz" v]
But is there a simpler way?
Thanks.
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
I doubt you could find much shorter code to do it, but depending on how long your strings are, there may be more efficient methods. You're using a FIND for every character in the string, which might make the process slow with long strings.
Alternative approaches could be a routine to loop through the string comparing the characters, (note you'd need to compare #"a" as well as #"A"), or to use PARSE.
If you need examples for those just ask.
|
|
|
|
« Last Edit: January 12, 2005, 12:09:18 AM by CarlRead »
|
Logged
|
- Carl Read
|
|
|
Vincent
Guest
|
Not simpler, but faster:
"trim/with" removes all specified caracters from a string.
trim/with string "abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ"
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
Not simpler, but faster: Doh! Pity there's not more monitoring this forum - that answer should've arrived a lot quicker.
|
|
|
|
|
Logged
|
- Carl Read
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2287 Posts in 593 Topics by 3732 Members
Latest Member: Hentai40
|