1. Parsing This Line

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! grin

EDIT 2: Ummm. Maps aren't really for "records." OK, what is?

new topic     » topic index » view message » categorize

2. Re: Parsing This Line

include std/sequence.e 
include std/console.e 
 
 
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"""  
 
 
 
procedure get_field( sequence line, sequence lookfor ) 
    line  = split( line, '&' ) 
 
    for i=1 to length(line) do 
        line[i] = split( line[i], '=' ) 
        if match( lookfor, line[i][1] ) then 
            puts(1, line[i][2] ) 
            exit 
        end if 
    end for 
 
end procedure 
 
 
get_field( line, "company" ) 

Billy's Operating Company

The fancy stuff I leave to you... _tom

new topic     » goto parent     » topic index » view message » categorize

3. Re: Parsing This Line

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! grin

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.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Parsing This Line

Thank you, guys!

Gives me something to work with.

new topic     » goto parent     » topic index » view message » categorize

5. Re: Parsing This Line

There's also a routine inside the standard library that may help you with it http://openeuphoria.org/docs/std_net_url.html#_5336_parse_querystring
It may not be most efficient but it's good that you can depend on a tested and common code.

edit: s/route/routine + a

new topic     » goto parent     » topic index » view message » categorize

6. Re: Parsing This Line

gbonvehi said...

There's also a routine inside the standard library that may help you with it http://openeuphoria.org/docs/std_net_url.html#_5336_parse_querystring
It may not be most efficient but it's good that you can depend on a tested and common code.

edit: s/route/routine + a

Good discovery.

The docs have a typo that must be be fixed. The solution now looks like:

include std/net/url.e 
include std/map.e 
include std/console.e 
  
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"""   
  
  
map qs = parse_querystring( line ) 
 
display( map:get(qs, "company" ) ) 
 
--> Billy's Operating Company 

thanks for showing this solution

_tom

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu