Alternate TRIM need
[1/4] from: jinman:uwf at: 24-Aug-2004 13:50
I need to trim a string's delimiters. Is there a built in function for
this?
Or does someone have a nice function?
EXAMPLE:
PhoneString: {"123-4567"}
>> Print PhoneString
123-4567
** See, it has quotes
around it.. I don't want the quotes.
*** This is what I am looking for..
>> x: NewTrim/delimiter PhoneString {"}
>> print x
123-4567 ** See, the quotes are
gone.
Where newTrim by itself will trim spaces..
And with the "/delimiter" attribute.. it will take a character the would be
the field delimiter.
John.
[2/4] from: SunandaDH:aol at: 24-Aug-2004 15:07
Jim:
> I need to trim a string's delimiters. Is there a built in function for
> this?
>
> Or does someone have a nice function?
PhoneString: {"123-4567"}
print trim/with phonestring {"}
123-4567
trim/with will remove *all* "s not just the first and last:
PhoneString: {"1"2"3"-4"567"}
print trim/with phonestring {"}
123-4567
Good enough?
Sunanda
[3/4] from: moliad:aei:ca at: 24-Aug-2004 20:52
John W. Inman Jr. wrote:
> I need to trim a string's delimiters. Is there a built in function for
> this?
>
> Or does someone have a nice function?
trim has a /with refinement which should do specifically what you want...
>> print trim/with {"123-4567"} {"}
123-4567
PS: try the help function in the console... it gives many questions :-)
ex:
> 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)
HTH!
-MAx
[4/4] from: carl::cybercraft::co::nz at: 25-Aug-2004 23:01
>=== Original Message >
>Jim:
<<quoted lines omitted: 11>>
>Good enough?
>Sunanda
If not, then perhaps something like this...
trim-delims: func [str [string!] delims[char! string!]][
if not empty? str [
delims: join delims/1 last delims
if delims/2 = last str [remove back tail str]
if (to-string delims/1) = copy/part str 1 [remove str]
]
str
]
It accepts one character for when the start and end deliminaters are the same and two
for when they're different. in use...
>> trim-delims "" {"}
== ""
>> trim-delims "a" {"}
== "a"
>> trim-delims {"a"} {"}
== "a"
>> trim-delims "{a}" {"}
== "{a}"
>> trim-delims "{a}" "{}"
== "a"
>> trim-delims "<abc>" "<>"
== "abc"
then again, perhaps LOAD does all you need? ...
>> load {"123-4567"}
== "123-4567"
Hmmm. :-)
-- Carl Read
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted