replace - Gimp脚本Fu中的字符串替换

标签 replace str-replace gimp script-fu

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

最佳答案

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

(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 "")
    )
)

关于replace - Gimp脚本Fu中的字符串替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11509500/

相关文章:

java - 在 Java 中替换单词时保持相同的大小写

c# - 在 C# 中根据 CSV 文件中的映射搜索和替换文本文件的内容

javascript正则表达式捕获括号

python - Gimp:如何使用 python 脚本将图像导出为没有颜色空间信息的 BMP?

python - 如何在GimpFU中传递图像路径

javascript - 通过 HTML 代码中的搜索和替换填写协议(protocol)相关 URL

regex - 如何使用 Notepad++ 正则表达式搜索匹配 HTML 属性?

带有变量的 PHP 模板类?

regex - 如何仅在 powershell 的子字符串中替换特定字符

python - 在 Gimp 中使用 Python 从图层组获取子图层