2

次のようなキー/値パリ別名クエリ文字列の文字列を解析する方法については何も見つかりません。

FieldType="String"&FieldFormat="^[a-z0-9!#$%&'*+/=?^_`{|}~-]+$"

上記の例のように、フィールド区切り文字が値に含まれる場合があります。これは Web 要求のパラメーターリストとして使用されません。

私はこれを見つけました:アイテムのコンマ区切りリストでループを実行すると4GLが進行します

ただしentry()、データが引用符内にあるかどうかは気にしません。

=編集=

だから私は誰も真似する必要がないことを願っているあまり理想的ではない解決策を見つけました

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 ステートメントは、悪夢を構成するものです。

4

4 に答える 4

1

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.
于 2015-06-05T12:19:11.550 に答える
1
define variable qryString as character no-undo.

define variable sep1 as character no-undo.
define variable sep2 as character no-undo.
define variable trimlist as character no-undo.

define variable sep1pos as integer no-undo.
define variable sep2pos as integer no-undo.

define variable part1 as character no-undo format "x(60)".
define variable part2 as character no-undo format "x(60)".

define variable name1 as character no-undo format "x(60)".
define variable name2 as character no-undo format "x(60)".

define variable valu1 as character no-undo format "x(60)".
define variable valu2 as character no-undo format "x(60)".

qryString = 'FieldType="String"&FieldFormat="^[a-z0-9!#$%&~'*+/=?^_`~{|}~~-]+$"'.

sep1 = '&'.
sep2 = '='.
trimlist = '"' + "'".

sep1pos = index( qryString, sep1 ).
part1 = substring( qryString, 1, sep1pos - 1 ).
part2 = substring( qryString, sep1pos + 1 ).

sep2pos = index( part1, sep2 ).
name1 = trim( substring( part1, 1, sep2pos - 1 ), trimlist ).
valu1 = trim( substring( part1, sep2pos + 1 ), trimlist ).

sep2pos = index( part2, sep2 ).
name2 = trim( substring( part2, 1, sep2pos - 1 ), trimlist ).
valu2 = trim( substring( part2, sep2pos + 1 ), trimlist ).

    display
      part1 skip
      part2 skip
      name1 skip
      valu1 skip
      name2 skip
      valu2 skip
     with
      side-labels
    .

(引用符で囲まれた文字列内に "~" を使用して特殊文字をエスケープし、入力ソースから取得するのではなく、プログラムに含めるようにしました。実際には、qryString はおそらくプログラムに埋め込まれていません。)

于 2015-06-04T16:05:15.320 に答える
0

キーのリストがわかっている場合は、INDEX 関数を使用してすべてのキー名の開始位置を見つけ、SUBSTRING を使用して文字列を分離できます。

display INDEX(<yourvar>,"&FieldFormat").

NUM-ENTRIES および ENTRY で追加のオプションを使用して、使用する区切り文字 ('"') を提供することもできますが、それが他の引用符内に表示されない場合に限ります。

于 2015-06-04T14:02:58.577 に答える