Parsing Key Value Pairs From Shell Command Results

I recently saw a post asking how in Xojo to parse a data dump that was returned from a shell.result into key value pairs.

dim Rows() as string
//remove any extra line feed chars
data=replaceall(data,chr(10),"") 
//remove any qoutes
data=replaceall(data,chr(34),"") 
//break each row by chr(13) Carriage Return 
//CHR(13) might need to be updated depending on the target OS
rows()=data.Split(chr(13)) 
for each s as string in rows
dim key as string
dim value as string
key=trim(NthField(s,"=",1))
value=trim(NthField(s,"=",2))
next

The code above will break the returned result into rows then break each row into a KEY and VALUE variable from which you can do what ever the applicaiton needs.

Leave a Reply

Your email address will not be published. Required fields are marked *