How trim?
Marielle Lange
mlange at lexicall.org
Mon Oct 24 17:15:42 EDT 2005
Hi Bob,
You could also use regular expressions.
put LTrim(RTrim(" The cat sat under the mat " )) into tResult
function LTrim pText
get matchtext(pText, "(^[ \t]*(.*))", tFull, tPart)
replace tFull with tPart in pText;
return pText
end function
function RTrim pText
get matchtext(pText, "((.*)[ \t]*$)", tFull, tPart)
replace tFull with tPart in pText;
return pText
end function
(^ means start of word, $ means end of word; . means any
character; .* means any number (0 to many) of any character; [ \t]
means either space or tab (I added tab in case you want to remove
initial tabs as well).
> Bob Warren wrote:
>
>> Sometimes inexperienced Rev programmers have to ask questions that
>> make them want to crawl under the table in shame because probably
>> the answer is idiotically simple. Here is such a question.
>>
>> If I have a string, say:-
>>
>> " The cat sat under the mat "
>>
>> - and I want to trim off the leading and following blanks to give:-
>>
>> "The cat sat on the mat"
>>
>>
> put word 1 to -1 of myVar into mySecondVar
>
> Trimming only one end is slightly harder - in fact, the best way I
> can think of is surprisingly complex
> put char 1 to -2 of (word 1 to -1 of (t & "=")) -- could have
> been any non-space character
> put char 2 to -1 of (word 1 to -1 of ("=" & t)) -- could have
> been any non-space character
>
>
> Hopefully someone else will come up with an easier way, and I will
> slap my head in annoyance :-)
>
------------------------------------------------------------------------
--------
Marielle Lange (PhD), Psycholinguist
Alternative emails: mlange at blueyonder.co.uk, M.Lange at ed.ac.uk
Homepage
http://homepages.lexicall.org/mlange/
Easy access to lexical databases http://lexicall.org
Supporting Education Technologists http://
revolution.lexicall.org
More information about the use-livecode
mailing list