How To: Manage columns of data (was Re: How To: Delete columns of data)

Peter M. Brigham pmbrig at gmail.com
Sat Sep 6 07:24:43 EDT 2014


That was fun! And useful!

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig

On Sep 6, 2014, at 5:44 AM, FlexibleLearning.com wrote:

> Peter:  Thank you for adding column ranges.
> Mike: Thank you for the column extraction handler.
> 
> I believe this summarises our efforts to date. It includes column ranges and
> the ability to either delete or extract columns of data from a table. I
> accept that optimisation has been compromised in favour of code brevity when
> extracting columns, but the time overhead is negligible. 
> 
> function manageColumns pData,pCols,pAction,pDelim
>  -- Purpose: To delete or extract specified columns from a table
>  -- Syntax: manageColumns <data>,<cols>,<action>[,<delim>]
>  --     data: Specifies the data to parse
>  --     cols: A comma separated list of columns or column ranges to be
> removed or extracted
>  --         for example "2,5,7"
>  --         or a column range: "3-5"
>  --         or a combination "2,4-5,7,9-11,"
>  --     action: Either "delete" or "extract"
>  --     delim: Optional column separator for example "," or "|"
>  --         if unspecified, defaults to TAB
>  -- By: Hugh Senior, based on handlers by Michael Doub, based on a handler
> by Peter M. Brigham, based on a handler by Hugh Senior, Use-LC list
> 
>  if pCols ="" then return pData
>  if pDelim <>"" then set the columnDelimiter to pDelim
>  repeat for each item tCol in pCols
>    if "-" is in tCol then
>      set the itemDel to "-"
>      repeat with i = item 1 of tCol to item -1 of tCol
>        put i & comma after pColsExpanded
>      end repeat
>      set the itemDel to comma
>    else
>      put tCol & comma after pColsExpanded
>    end if
>  end repeat
>  put char 1 to -2 of pColsExpanded into pCols
>  split pData by column
>  put item 2 of extents(pData) into tMax
>  repeat with n=1 to tMax
>    if pAction="delete" then get (n is NOT among the items of pCols)
>    else get (n is among the items of pCols)
>    if it 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 manageColumns
> 
> 
> 
> Hugh Senior
> FLCo
> 
> 
> 
> _______________________________________________
> 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