regEx to remove spaces ?
Mark Schonewille
m.schonewille at economy-x-talk.com
Thu May 18 04:54:17 EDT 2006
Hi Alex,
You're right about the additional assumptions, although one might
call the function within another repeat loop for each line, if each
pair of quotes is in one single line. As other solutions have shown,
one may also replace the return with a unique string before calling
this function.
As to the spaces, one will not want to apply any of the available
solutions, if the number of characters of the new string needs to be
equal to the number of characters of the old string and normally you
don't want to have 2 spaces subsequently. It is possible, though, to
apply another correction, by adding spaces as necessary. Also,
starting and trailing spaces of the entire text would have to be
added. All other spaces are included in the new string.
Best,
Mark
--
Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz
Salery is the easiest way to get your own web store on-line: http://
www.salery.biz/salery.html
Op 17-mei-2006, om 17:47 heeft Alex Tweedly het volgende geschreven:
> Mark Schonewille wrote:
>
>> Again, no regex. I looked into regex, but I can't find how to
>> replace quoted strings without knowing the whole string in
>> advance. It would be great if someone came up with a regex
>> solution for this. In the mean time, this function seems to do
>> the job quite nicely:
>>
>> function decentQuotes theStr
>> set the itemDel to space
>> repeat for each word myWord in theStr
>> if number of items of myWord > 1
>> then put quote & word 1 to -1 of (char 2 to -2 of myWord) & ¬
>> quote & space after myNewStr else put myWord & space after
>> myNewStr
>> end repeat
>> return char 1 to -2 of myNewStr
>> end decentQuotes
>>
>>
> I think it also assumes the input string is on a single line, since
> cr is a word delimiter, so input like
>
>> first line
>> second line
>
>
> becomes
>
>> first line second line
>
>
> And input like ("."s to indicate where the spaces are ....)
>
>> first ".line..
>> ..second.." line
>
>
> get badly mangled into
>
>> first "line" second "lin"
>
More information about the use-livecode
mailing list