【问题标题】:String Replace in Gimp Script FuGimp Script Fu 中的字符串替换
【发布时间】:2012-07-15 14:34:18
【问题描述】:

我有一个重命名文件的 Gimp 插件,我需要一个替换功能。不幸的是,Gimp 使用的 TinyScheme 没有字符串的替换功能。我搜索了很多,但找不到一个真正的字符串替换。回答要关注...

【问题讨论】:

    标签: replace str-replace gimp script-fu


    【解决方案1】:

    这是我创建的实现。如果有更好的解决方案,请随时告诉我。

    (define (string-replace strIn strReplace strReplaceWith)
        (let*
            (
                (curIndex 0)
                (replaceLen (string-length strReplace))
                (replaceWithLen (string-length strReplaceWith))
                (inLen (string-length strIn))
                (result strIn)
            )
            ;loop through the main string searching for the substring
            (while (<= (+ curIndex replaceLen) inLen)
                ;check to see if the substring is a match
                (if (substring-equal? strReplace result curIndex (+ curIndex replaceLen))
                    (begin
                        ;create the result string
                        (set! result (string-append (substring result 0 curIndex) strReplaceWith (substring result (+ curIndex replaceLen) inLen)))
                        ;now set the current index to the end of the replacement. it will get incremented below so take 1 away so we don't miss anything
                        (set! curIndex (-(+ curIndex replaceWithLen) 1))
                        ;set new length for inLen so we can accurately grab what we need
                        (set! inLen (string-length result))
                    )
                )
                (set! curIndex (+ curIndex 1))
            )
           (string-append result "")
        )
    )
    

    【讨论】:

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