【问题标题】:How to Remove special characters from name-value pairs in the Webspeed URL?如何从 Webspeed URL 中的名称-值对中删除特殊字符?
【发布时间】:2023-04-07 21:40:02
【问题描述】:

我需要删除包含名称-值对的 Webspeed URL 中存在的回车符和换行符。如何做到这一点?请有任何想法!

【问题讨论】:

    标签: progress-4gl openedge webspeed


    【解决方案1】:

    要替换字符,您可以使用 REPLACE 函数

    REPLACE function
    Returns a string with specified substring replacements.
    Syntax 
    REPLACE ( source-string , from-string , to-string ) 
    

    例子:

    DEFINE VARIABLE cTxt    AS CHARACTER   NO-UNDO FORMAT "x(20)".
    DEFINE VARIABLE cNewTxt AS CHARACTER   NO-UNDO FORMAT "x(20)".
    
    cTxt = "abc123abc123abc123".
    
    cNewTxt = REPLACE(cTxt, "a", "-").
    
    DISPLAY cNewTxt .
    

    您可以使用控制代码定位新行 ~n

    REPLACE(cString, "~n", "replacing character").
    

    或针对单个 %0d(十进制 ascii 代码 13)和 %0a(十进制 ascii 代码 10)。

    REPLACE(cString, CHR(13), "replacing character").
    REPLACE(cString, CHR(10), "replacing character").
    

    【讨论】:

      【解决方案2】:

      我最近需要做这样的事情,发现以下内容非常方便。这可能有点激烈——它会删除所有控制代码和任何高于 ascii 126 的代码。但是您可以轻松地调整这些限制。 (我的用途是填充文本字段——所以所有这些内容对我来说都是非法输入。)

      define variable hd as character no-undo initial "0123456789ABCDEF".
      
      function hex2char returns character ( h as character ):
      
        define variable i as integer no-undo.
      
        if length( h ) <> 2 or index( hd, substring( h, 1, 1 )) < 0 or index( hd, substring( h, 2, 1 )) < 0 then
          return "".
      
        i = ((( index( hd, substring( h, 1, 1 )) - 1 ) * 16 ) +
                index( hd, substring( h, 2, 1 )) - 1
            ).
      
        if i < 32 or i >= 127 then
          return "".
         else
          return chr( i ).
      
      end.
      
      function url-decode returns character ( input url as character ):
      
        define variable xurl as character no-undo.
        define variable zurl as character no-undo.
      
        define variable pct as integer no-undo.
      
        /* fix known trouble makers
         */
      
        assign
          xurl = replace( url, "+", " " )
          xurl = replace( xurl, "%0A%0D", "~n" )      /* <LF><CR>     */
          xurl = replace( xurl, "%0D%0A", "~n" )      /* <CR><LF>     */
          xurl = replace( xurl, "%0D",    "~n" )      /* <CR>         */
        .
      
        pct  = index( xurl, "%" ).
      
        do while pct > 0 and xurl > "":
          assign
            zurl = zurl + substring( xurl, 1, pct - 1 ) + hex2char( substring( xurl, pct + 1, 2 ))
            xurl = substring( xurl, pct + 3 )
            pct  = index( xurl, "%" )
          .
        end.
      
        return zurl + xurl.
      
      end.
      
      display url-decode( sampleUrl ) view-as editor size 60 by 25.
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-02-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多