Replace Gimp脚本中的字符串替换
我有一个Gimp插件,可以重命名文件,我需要一个替换函数。不幸的是,Gimp使用的TinyScheme没有字符串替换函数。我搜索了很多,但没有找到一个真正的字符串替换。下面是我创建的实现。如果有更好的解决方案,请随时告诉我Replace Gimp脚本中的字符串替换,replace,str-replace,gimp,script-fu,Replace,Str Replace,Gimp,Script Fu,我有一个Gimp插件,可以重命名文件,我需要一个替换函数。不幸的是,Gimp使用的TinyScheme没有字符串替换函数。我搜索了很多,但没有找到一个真正的字符串替换。下面是我创建的实现。如果有更好的解决方案,请随时告诉我 (define (string-replace strIn strReplace strReplaceWith) (let* ( (curIndex 0) (replaceLen (string-leng
(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 "")
)
)
(定义(字符串替换strIn strReplace strReplace为)
(让*
(
(curIndex 0)
(替换(字符串长度替换))
(替换为len(字符串长度替换为))
(输入(字符串长度)
(结果)
)
;在主字符串中循环搜索子字符串
(而(