5

ファイルの名前を変更する Gimp プラグインがあり、置換機能が必要でした。残念ながら、Gimp が使用する TinyScheme には文字列の置換機能がありません。私はたくさん検索しましたが、真の文字列置換として機能するものを見つけることができませんでした. フォローする答え...

4

1 に答える 1

7

これが私が作成した実装です。より良い解決策がある場合は、お気軽にお知らせください。

(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 "")
    )
)
于 2012-07-17T15:54:26.200 に答える