progress 4gl OpenEdge parse key/value-pair string aka Query-String -
i cant find on how should parse string of key/value paris aka query-string one:
fieldtype="string"&fieldformat="^[a-z0-9!#$%&'*+/=?^_`{|}~-]+$"
field separators might contained in value above example not used web-request paramlist.
i found this: running loop on comma delimited list of items progress 4gl
but entry()
not care if data in qoutation.
= edit =
so found not ideal solution hope nobody needs mimic
do jj=1 num-entries(curr,"&"): define variable pos integer no-undo. assign k = entry( 1, entry(jj,curr,"&"), "=") v = entry( 2, entry(jj,curr,"&"), "=") pos = index( curr, k + "=" ). /* check if qouted value*/ if num-entries( substring( curr, pos, abs( index(curr, "&", pos) - pos) ) ,'"') > 1 assign v = entry( 2, substring( curr, pos) , '"'). end.
the if-statment nightmares made of!
building tom's , themaddba's answers.
assumption: first & 1 want split on.
define variable cqrystring character no-undo. define variable isplitindex integer no-undo. define variable ctype character no-undo format "x(30)" label " type". define variable cformat character no-undo format "x(30)" label "format". assign cqrystring = 'fieldtype=string&fieldformat="^[a-z0-9!#$%&~'*+/=?^_`~{|}~~-]+$"' isplitindex = index(cqrystring, "&") ctype = substring(cqrystring, 1, isplitindex - 1) cformat = substring(cqrystring, isplitindex + 1, length(cqrystring)) ctype = substring(ctype, index(ctype, "=") + 1, length(ctype)) cformat = substring(cformat, index(cformat, "=") + 1, length(cformat)) . assign ctype = entry(2, ctype, '"') when substring(ctype, 1, 1) = '"'. assign cformat = entry(2, cformat, '"') when substring(cformat, 1, 1) = '"'. display ctype skip cformat side-labels.
Comments
Post a Comment