Friday, July 30, 2010

#1 2006-11-30 02:08:06 pm

Bruce Phillips
Administrator
Registered: 2004-07-15
Posts: 2647

explode_ignoring() [split/delimit text]

This handler will "explode" a string (using text item delimiters) while ignoring content inside another delimiter. (It was created for this thread: Ignore Delimiter Inside Quotes)

Applescript:

on explode_ignoring(someDelimiter, someText, ignoreInsideThis)
   local someDelimiter, someText, ignoreThis, explosion, ASTID, thisItem
   
   set explosion to {}
   set ASTID to AppleScript's text item delimiters
   set AppleScript's text item delimiters to {ignoreInsideThis}
   set someText to text items of someText
   set AppleScript's text item delimiters to {someDelimiter}
   get count someText
   
   repeat with i from 1 to result
       if (i mod 2) is 1 then -- only process odd-numbered items
           get text items of someText's item i
           
           repeat with thisItem in result
               tell thisItem's contents to if it is not "" then set explosion's end to it
           end repeat
       else
           set explosion's end to someText's item i
       end if
   end repeat
   
   set AppleScript's text item delimiters to ASTID
   return explosion
end explode_ignoring

-- Example
explode_ignoring(",", "22,\"Hello, World!\",a", "\"")
--> {"22", "Hello, World!", "a"}

See also: explode()

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.124 seconds, 9 queries executed ]

RSS (new topics) RSS (active topics)