LTRIM, RTRIM

Yves COPPE yvescoppe at skynet.be
Wed Dec 14 13:29:59 EST 2005


Le 14-déc.-05 à 14:07, Jerry Muelver a écrit :

> Are there in RF functions complementary to BASIC's RTRIM and LTRIM  
> functions? Or, is this kind of chunk manipulation a "do it  
> yourself" project?
>
> I have
> .title, Going Home




i have found such functions in the archives :

function libString_rtrim inputString
   # Syntax...: libString_rtrim inputString [charlist]
   # Details..: This function returns a string with whitespace  
stripped from the end of the inputString.
   #          : Without the second parameter the following characters  
will get stripped:
   #          :   SPACE (ASCII 32 (0x20)), an ordinary space
   #          :   TAB   (ASCII  9 (0x09)), a tab
   #          :   LF    (ASCII 10 (0x0A)), a new line (linefeed)
   #          :   CR    (ASCII 13 (0x0D)), a carriage return
   #          :   NUL   (ASCII  0 (0x00)), a NUL-byte
   #          :         (ASCII 11 (0x0B)), a vertical tab
   #          : You can also specify additional characters you want  
to strip by passing a comma delimited list as the optional
   #          : second parameter (charlist).
   local charlist
   put SPACE & COMMA & TAB & COMMA & LF & COMMA & CR & COMMA &  
numToChar(0) & COMMA & numToChar(11) into charlist
   -- check to see if there was additional characters passed to be  
added to the charlist
   if (paramCount() = 2) then
     put COMMA & param(2) after charlist
   end if
   -- trim off the extra characters
   repeat
     if (char -1 of inputString is among the items of charlist) then
       delete char -1 of inputString
     else
       exit repeat
     end if
   end repeat
   return inputString
end libString_rtrim

function libString_ltrim inputString
   # Syntax...: libString_ltrim inputString [charlist]
   # Details..: This function returns a string with whitespace  
stripped from the beginning of the inputString.
   #          : Without the second parameter the following characters  
will get stripped:
   #          :   SPACE (ASCII 32 (0x20)), an ordinary space
   #          :   TAB   (ASCII  9 (0x09)), a tab
   #          :   LF    (ASCII 10 (0x0A)), a new line (linefeed)
   #          :   CR    (ASCII 13 (0x0D)), a carriage return
   #          :   NUL   (ASCII  0 (0x00)), a NUL-byte
   #          :         (ASCII 11 (0x0B)), a vertical tab
   #          : You can also specify additional characters you want  
to strip by passing a comma delimited list as the optional
   #          : second parameter (charlist).
   local charlist
   put SPACE & COMMA & TAB & COMMA & LF & COMMA & CR & COMMA &  
numToChar(0) & COMMA & numToChar(11) into charlist
   -- check to see if there was additional characters passed to be  
added to the charlist
   if (paramCount() = 2) then
     put COMMA & param(2) after charlist
   end if
   -- trim off the extra characters
   repeat
     if (char 1 of inputString is among the items of charlist) then
       delete char 1 of inputString
     else
       exit repeat
     end if
   end repeat
   return inputString
end libString_ltrim


Hope this helps

Greetings.

Yves COPPE
yvescoppe at skynet.be




More information about the use-livecode mailing list