How To: Delete columns of data

JB sundown at pacifier.com
Fri Sep 5 19:08:29 EDT 2014


All 3 of you have posted some fantastic code!

Thank you, Hugh, Peter and Mike.  I can use it
to solve some problems.

John Balgenorth



On Sep 5, 2014, at 4:09 PM, Peter M. Brigham <pmbrig at gmail.com> wrote:

> Great!
> 
> -- Peter
> 
> Peter M. Brigham
> pmbrig at gmail.com
> http://home.comcast.net/~pmbrig
> 
> On Sep 5, 2014, at 1:51 PM, Michael Doub wrote:
> 
>> Here is an even more general version:
>> 
>> function deleteColumns pData,pColsToDelete,pDelim
>>  -- delete specified columns from a table
>>  -- Syntax: deleteColumns <data>,<cols>[,<delim>]
>>  --     data: Specifies the data to parse.
>>  --     cols: A comma separated list of columns or column ranges to be removed,
>>  --         for example "2,5,7"
>>  --         or a column range: "3-5"
>>  --         or a combination "2,4-5,7,9-11,"
>>  --     delim: Optional column separator for example "," or "|"
>>  --         if unspecified, defaults to tab.
>>  -- based on a handler by Hugh Senior and Peter M. Brigham, Use-LC list
>> 
>>  -- requires getItem()
>> 
>>  if pColsToDelete = empty then return pData
>>  repeat for each item pCol in pColsToDelete
>>     if "-" is in pCol then 
>>        put getItem(pCol,1,"-") into firstColNbr
>>        put getItem(pCol,2,"-") into lastColNbr
>>        repeat with i = firstColNbr to lastColNbr
>>           put i & comma after pColsToDeleteExpanded
>>        end repeat
>>     else
>>        put pCol & comma after pColsToDeleteExpanded
>>     end if
>>  end repeat
>>  put char 1 to -2 of pColsToDeleteExpanded into pColsToDelete
>>  if pDelim = empty then put tab into pDelim
>>  set the columnDelimiter to pDelim
>>  split pData by column
>>  put item 2 of extents(pData) into tMax
>>  repeat with n=1 to tMax
>>     if n is NOT among the items of pColsToDelete then
>>        add 1 to x
>>        put pData[n] into pData[x]
>>     end if
>>  end repeat
>>  repeat with n=x+1 to tMax
>>     delete local pData[n]
>>  end repeat
>>  combine pData by column
>>  return pData
>> end deleteColumns
>> 
>> function getItem tList,tIndex,tDelim
>>  -- returns item # tIndex of tList, given itemdelimiter = tDelim
>>  -- could just "get item tIndex of tList" in the calling handler but
>>  --    then have to set and restore the itemDelimiter, so this is less hassle
>>  -- defaults to tDelim = comma
>> 
>>  if tDelim = empty then put comma into tDelim
>>  set the itemdelimiter to tDelim
>>  return item tIndex of tList
>> end getItem
>> 
>> 
>> 
>> On Sep 5, 2014, at 10:58 AM, Peter M. Brigham <pmbrig at gmail.com> wrote:
>> 
>>> Peter M. Brigham
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
> 





More information about the use-livecode mailing list