How to replace just the first found space with tab for all lines in a variable?

Jim Ault jimaultwins at yahoo.com
Wed May 25 23:39:35 EDT 2011


On May 25, 2011, at 8:41 AM, Alex Tweedly wrote:

> Beware this will get the (possibly) wrong result for some data. For  
> instance, a comma will terminate a word, so
>
> a,b def
>
> will give you a key of "aTABb def"

> rather than a key of "a,TABdef"
>


Punctuation is not considered a word delimiter, so the comma will  
remain attached to the string.

put word 1 of "a,b def" into msg
-- I get "a,b" using Rev 3.5

In fact, if the words have trailing commas, the punctuation is  
considered part of the word

put word 2 of "He spoke, therefore he was heard"
=>  the 6 chars     'spoke,'

put word 2 of "nice ,,and,,,,,,,,,, warm"
=>   ,,and,,,,,,,,,,

put word 2 of "really ...-and_,;]/><? truly"
=>  ...-and_,;]/><?

Hope this helps


Jim Ault
Las Vegas

On May 25, 2011, at 8:41 AM, Alex Tweedly wrote:

> Beware this will get the (possibly) wrong result for some data. For  
> instance, a comma will terminate a word, so
>
> a,b def
>
> will give you a key of "aTABb def"
>
> rather than a key of "a,TABdef"
>
> I'd stick to the safer
>
> set the itemDel to space
> repeat for each line L in tData
>   put item 1 of L & TAB & item 2 to -1 of L & CR after tOutput
> end repeat
>
>
> or ... since they are key/value pairs, if (AND ONLY IF) you happen  
> to know that the keys are unique
>
> split tData by CR and space
> combine tData by CR and TAB
>
> -- Alex.
>
> On 25/05/2011 16:14, Keith Clarke wrote:
>> Thanks to Roger, Ken and Chris for playing - but Jim gets the prize  
>> for the simplicity brought through passing data out to a second  
>> variable, line by line, rather than trying to fix the data in place  
>> (which is an interesting mental challenge but quite convoluted).
>>
>> So, I settled on this four line fix variant on Jim's first solution  
>> (I found that had to declare the line explicitly for each word chunk)
>>
>>    repeat for each line tLine in tSourceList
>>       put word 1 of tLine&  tab&  word 2 to -1 of tLine&  return  
>> after tResultTable
>>    end repeat
>>    filter tResultTable without empty
>>
>> So, I now have a nice, clean label-value table field.
>>
>> Nice that variables are 10 a penny in LiveCode! :-)
>> Best,
>> Keith..
>>

Jim Ault
Las Vegas






More information about the use-livecode mailing list