Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Using parse to eliminate trailing spaces
Pages: [1] Print
Author Topic: Using parse to eliminate trailing spaces  (Read 618 times)
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Using parse to eliminate trailing spaces
« on: January 18, 2007, 08:36:42 PM »

The funtion below is supposed to remove trailing spaces from any string variable presented to it.

It goes a long way but the bottom line is .......they are still there when the funtion returns to the calling point.  What's missing ?

space-strip: func [var] [
   digit: charset [#"0" - #"9"]
   alpha: charset [#"A" - #"Z" #"a" - #"z"]
   alphanum: union alpha digit
   reverse var
   parse/all var [" " skip alphanum copy/part var to end]
   reverse var
]   
Logged
Graham
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: Using parse to eliminate trailing spaces
« Reply #1 on: January 19, 2007, 01:39:22 AM »

Try using complement ..

 space: charset [ #" " ]
 nonspace: complement space
 parse/all "abcd    " [ copy data some nonspace ]

Logged

Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
Re: Using parse to eliminate trailing spaces
« Reply #2 on: January 19, 2007, 03:18:18 AM »

BTW, do you know about TRIM ?

Code:
>> help trim
USAGE:
    TRIM series /head /tail /auto /lines /all /with str

DESCRIPTION:
     Removes whitespace from a string. Default removes from head and tail.
     TRIM is an action value.

ARGUMENTS:
     series -- (Type: series port)

REFINEMENTS:
     /head -- Removes only from the head.
     /tail -- Removes only from the tail.
     /auto -- Auto indents lines relative to first line.
     /lines -- Removes all line breaks and extra spaces.
     /all -- Removes all whitespace.
     /with
         str -- Same as /all, but removes characters in 'str'. (Type: char string)
Logged
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Re: Using parse to eliminate trailing spaces
« Reply #3 on: January 20, 2007, 06:29:00 AM »

Clearly I don't know too much yet :-) :-)

But also clearly,  either of these suggestions will make things right

Thank you.

John D.

Logged
Graham
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: Using parse to eliminate trailing spaces
« Reply #4 on: January 20, 2007, 12:33:45 PM »

Oops .. I assumed that you knew about trim and wanted to learn how to do it using parse!
Logged

Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Using parse to eliminate trailing spaces
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 02, 2008, 08:29:32 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2311 Posts in 595 Topics by 4144 Members
Latest Member: FinoDiato

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

RT design by Defiant Pc