Re: Parsing This Line
- Posted by jimcbrown (admin) Mar 31, 2015
- 1241 views
euphoric said...
What's the most efficient way to parse this line so I can do something like this:
line = "company=Billy's Operating Company&profile=Dori&user=Dori Setchell&form=aaplepca&inv=N/A&pc_id=1554165672&lic_path=C:\Documents and Settings\BillyRay\Application Data\Microsoft\Templates&win=Windows XP Professional&word=Word 2010" puts(1, get_field( line, "company" ) )
Output is
Billy's Operating Company
Obviously, it would probably be better to load up line into an object, but the above is a general idea.
Thanks!
EDIT 1: I just recalled maps. I bet they're useful here. Let's try that!
EDIT 2: Ummm. Maps aren't really for "records." OK, what is?
Don't know if this is the most efficient way to do it, but here's what I did:
function get_field(sequence line, sequence field) integer i = match(field, line) return line[i+length(field)+1..find('&', line, i)-1] end function sequence line = "company=Billy's Operating Company&profile=Dori&user=Dori Setchell&form=aaplepca&inv=N/A&pc_id=1554165672&lic_path=C:\\Documents and Settings\\BillyRay\\Application Data\\Microsoft\\Templates&win=Windows XP Professional&word=Word 2010" puts(1, get_field( line, "company" ) )
No maps involved.