gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:47:45 24 4
gpt4 key购买 nike

我有一个可以重命名文件的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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com