Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Removing characters
Pages: [1] Print
Author Topic: Removing characters  (Read 308 times)
jmatro
Newbie
*
Offline Offline

Posts: 7


View Profile
Removing characters
« on: January 11, 2005, 05:31:10 PM »

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


Email
Removing characters
« Reply #1 on: January 11, 2005, 06:06:48 PM »

Found one way to do it!!

    string: "1abc2def14xyz9"

    remove-each v string [find "abcdefghijklmnopqrstuvwxyz" v]

But is there a simpler way?

Thanks.
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
Removing characters
« Reply #2 on: January 12, 2005, 12:00:13 AM »

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


Email
Removing characters
« Reply #3 on: January 14, 2005, 08:14:10 PM »

Not simpler, but faster:

"trim/with" removes all specified caracters from a string.

trim/with string "abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ"
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
Removing characters
« Reply #4 on: January 14, 2005, 10:05:58 PM »

Quote
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] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Removing characters
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 20, 2008, 11:40:09 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2287 Posts in 593 Topics by 3732 Members
Latest Member: Hentai40

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc