alias addtest {
var %string = Rome, "Saudi Arabia", Sweden black pistol, machine gun
var %n = 1, %locations, %items
; loop comma-delimited tokens, tokenize the token
while ($gettok(%string,%n,44)) {
var %token = $v1
tokenize 32 %token
; looping "locations" so far
if (!%items) {
; token is no quote, and token contains a space char: split token found.
if (%token == $noqt(%token)) && ($2) {
; first part of split token belongs to "locations", second part to "items"
var %locations = $addtok(%locations,$1,44)
var %items = $2-
}
; it's not yet the split token: add this token to "locations" and remove possible quotes
else { var %locations = $addtok(%locations,$noqt($1-),44) }
}
; already looping "items": add this token to "items"
else { var %items = $addtok(%items,$1-,44) }
inc %n
}
ECHO -a locations: %locations
ECHO -a items: %items
}