替换字符串中的特定字符

问题描述 投票:0回答:1

我有这个 AppleScript 片段,可以很好地用 ' 替换 ` :

set strng to "Output`s new form should not be these'\\''chars"
set modifiedString to replaceChars(strng, "`", "'")

on replaceChars(inputText, charsOut, charsIn)
    set text item delimiters to charsOut
    set textList to text items of inputText
    set modifiedList to {}
    repeat with textItem in textList
        set end of modifiedList to textItem as text
    end repeat
    set text item delimiters to charsIn
    set resultText to modifiedList as text
    set text item delimiters to ""
    return resultText
end replaceChars

我想扩展它,以便它也搜索 '\'' 序列并替换为 ' 。 有点像:

set modifiedString to replaceChars(strng, {"`", "'\\''"}, "'")

如何过滤这个附加字符串?

注意,我也愿意通过 shell 命令执行此操作,但到目前为止,只有这种方法对我使用“`”字符有效。

shell applescript
1个回答
0
投票
set modifiedString to replaceChars(strng, {"`", "'\\''"}, "'")

...毕竟对我有用。 感谢您的投入

© www.soinside.com 2019 - 2024. All rights reserved.