Page 1 of 1 1
Topic Options
#81891 - 2003-10-15 02:41 PM LTrimstring(), RTrimstring() and Trimstring()
Pierre FREMION Offline
Getting the hang of it

Registered: 2000-01-11
Posts: 66
Loc: Paris, France, Europe, Sun3
Hello everybody.

Here are 3 functions I often use instead of LTrim(), RTrim() and Trim(), that I find

restrictives.

LTrimstring(), RTrimstring() and Trimstring()

In fact these functions do the same thing than LTrim(), RTrim() and Trim(), but I added

an optional argument which allow to change the default searched string 'Space' by the one

you indicate.

These 3 functions could replace LTrim(), RTrim() and Trim(), and because the second

argument is optional, previous scripts using these functions will still work as attended.

function LTrimString($a, optional $b)
$LTrimString=''
if vartype($b)=0 $b=' ' endif
if $a and $b and vartype($a)=8 and vartype($b)=8
while left($a,len($b))=$b
$a=substr($a,len($b)+1)
loop
$LTrimString=$a
endif
endfunction

function RTrimString($a, optional $b)
$RTrimString=''
if vartype($b)=0 $b=' ' endif
if $a and $b and vartype($a)=8 and vartype($b)=8
while right($a,len($b))=$b
$a=substr($a,1,len($a)-len($b))
loop
$RTrimString=$a
endif
endfunction

function TrimString($a, optional $b)
; Dependencies : Ltrimstring(), Rtrimstring
$TrimString=''
if vartype($b)=0 $b=' ' endif
if $a and $b and vartype($a)=8 and vartype($b)=8
$a=LTrimString($a,$b)
$a=RTrimString($a,$b)
$TrimString=$a
endif
endfunction

Try LTrimstring('\winnt','\')
and Trimstring(@ldrive,'\')
or Rtrimstring(@scriptname,'.kix')

Let me know if this helps or what you think about.

I wish you all a good day.
_________________________
Comments always welcome. French native so I apologize for my (mis)use of English!

Top
#81892 - 2003-10-16 04:10 AM Re: LTrimstring(), RTrimstring() and Trimstring()
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
These should have been posted in the UDF Forum.

Also, traditionally TRIM() has always only removed the starting/trailing spaces, thus KiXtart behaves consistent with other languages.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 476 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.127 seconds in which 0.066 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org