Page 1 of 1
no space at start and end line
Posted: Tue Feb 22, 2011 2:29 pm
by jmburnod
Hi All,
I need to delete first char and last char of a string if it is a space
I'm a little confuse with this script:
Code: Select all
function NoSPaceDebEndLine pLeT
repeat until char 1 of pLeT <> " " --•• work
delete char 1 of pLeT
wait 1 milliseconds
end repeat
repeat until char-1 of pLeT <> " " --•• dont work
delete char-1 of pLeT
wait 1 milliseconds
end repeat
return pLeT
end NoSPaceDebEndLine
I dont understand why the second repeat dont work
An other way tested is
Code: Select all
function NoSPaceDebEndLine pLeT
put the num of words of pLeT into nbw
return word 1 to nbw of pLeT
end NoSPaceDebEndLine
Re: no space at start and end line
Posted: Tue Feb 22, 2011 3:01 pm
by Dixie
hi...
Would this work for you ?
Code: Select all
on mouseUp
put line 1 of fld 1 into myVar
put stripSpace (myVar) into fld 2
end mouseUp
function stripSpace theString
repeat forever
if char 1 of theString = space then
delete char 1 of theString
else
exit repeat
end if
end repeat
repeat forever
if the last char of theString = space then
delete the last char of theString
else
exit repeat
end if
end repeat
return theString
end stripSpace
be well
Dixie
Re: no space at start and end line
Posted: Tue Feb 22, 2011 3:17 pm
by jmburnod
Hi,
No,
The second repeat dont work. WHY ?
All the best
Jean-Marc
Re: no space at start and end line
Posted: Tue Feb 22, 2011 4:23 pm
by dunbarx
Everybody's offerings seem to be sound, and they all work for me.
I tried them all on an string like: " aa bb cc " (one space before and two spaces after the text)
What are you getting as output?
Craig Newman
Re: no space at start and end line
Posted: Tue Feb 22, 2011 5:00 pm
by jmburnod
Hi Craig,
Yes it work with " aa bb cc "
The problem was in my string : The last char was a chartonum 13
Sorry for that
Best
Jean-Marc
Re: no space at start and end line
Posted: Tue Feb 22, 2011 5:35 pm
by dunbarx
So there are two ways to do this:
1- Work through the string, eliminating spaces at the beginning and spaces and returns at the end. This is easy and straightforward.
2- Let the chunking power of LC do all the work for you. This is a sneak attack, and actually much more elegant...
function stripSpacesAndReturns var
return word 1 to -1 of var
end stripSpacesAndReturns
Try it.
Craig Newman
Re: no space at start and end line
Posted: Tue Feb 22, 2011 5:50 pm
by Dixie
Craig...
Elegant indeed !
go steady
Dixie
Re: no space at start and end line
Posted: Tue Feb 22, 2011 5:55 pm
by jmburnod
Yes,
I tried this (the second script of my first message about this topic) but i thougt it was not the best way
Thank one more
Jean-Marc