我找不到任何关于如何解析一串键/值巴黎又名查询字符串的信息,如下所示:
FieldType="String"&FieldFormat="^[a-z0-9!#$%&'*+/=?^_`{|}~-]+$"
字段分隔符可能包含在值中,如上面的示例 这不能用作网络请求参数列表。
我发现了这个:running a loop on a comma delimited list of items progress 4GL
但是 entry()
并不关心数据是否在 qoutation 中。
= 编辑=
所以我找到了一个不太理想的解决方案,我希望没有人需要模仿
DO jj=1 TO NUM-ENTRIES(curr,"&"):
DEFINE VARIABLE pos AS INTEGER NO-UNDO.
ASSIGN
k = entry( 1, ENTRY(jj,curr,"&"), "=")
v = entry( 2, ENTRY(jj,curr,"&"), "=")
pos = INDEX( curr, k + "=" ).
/* Check if this is a qouted value*/
IF NUM-ENTRIES( SUBSTRING( curr, pos, ABS( INDEX(curr, "&", pos) - pos) ) ,'"') > 1 THEN
ASSIGN v = ENTRY( 2, SUBSTRING( curr, pos) , '"').
end.
IF 语句就是噩梦的组成部分!
最佳答案
根据 Tom 和 TheMadDBA 的答案构建。
假设:第一个 & 将是我们想要拆分的那个。
define variable cQryString as character no-undo.
define variable iSplitIndex as integer no-undo.
define variable cType as character no-undo format "x(30)" label " Type".
define variable cFormat as 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
with side-labels.
关于query-string - 进度 4gl OpenEdge 解析键/值对字符串又名查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30645576/