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

Keith Clarke keith.clarke at clarkeandclarke.co.uk
Wed May 25 13:54:25 EDT 2011


...thanks for the feedback and insights everyone.

Fortunately my script doesn't need to address every possible set of conditions that may arise. The source list contains a set of XML nodes and their contents, so item/word 1 will never contain punctuation - and the list has been pre-filtered for nodes with empty contents, so I don't have to worry about any trailing tabs. The output as a simple table field is to provide a read-only list by way of a 'status update' for a human observer - the follow-up scripts work from the returned XML file and its associated tree. 

However, the good points, well made here have made me wonder whether I can improve data quality upstream of the list field - to avoid this requirement completely.
Best,
Keith.. 
  
On 25 May 2011, at 17:18, Nonsanity wrote:

> Actually, "a,b" would be considered a single word both when using the "word
> of" format, as well as if the itemdel is space and you use "item of". In
> other words...
> 
> word 2 of "a,b cd ef"   =   "cd"
> and
> set itemdel to space
> item 2 of "a,b cd ef"  =  "cd"
> 
> The only real difference between the two forms is if there are runs of
> spaces between words, like so:
> 
> word 2 of "a,b[space][space]cd[space]ef"  =  "cd"
> and
> set itemdel to space
> item 2 of "a,b[space][space]cd[space]ef"  =  empty
> 
> The "item of" gives an empty result because it is returning the text between
> the first two spaces, and there's nothing there. As far as putting a tab
> after the first word, this version is functionally the same as the offset()
> method I described before, but I /think/ the offset() method would be
> faster.
> 
> Making simple conversion functions is very easy in LiveCode if you can make
> certain assumptions about the input data. The trick is often just finding
> the exceptions in large datasets that will trip up whichever function you
> pick.
> 
> I once had to convert several months of transactions in a library database
> between two formats using, I think, Supercard. It was the weird edge cases
> that tended to trip it up. I kept having to add special tests for those
> cases as they appeared.
> 
> ~ Chris Innanen
> ~ Nonsanity
> 
> 
> 
> On Wed, May 25, 2011 at 11:41 AM, Alex Tweedly <alex at tweedly.net> 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.
>> 





More information about the use-livecode mailing list