我有一个脚本,用于替换HTML等价物的重音字符,效果很好,但没有考虑字母的区分大小写。这会导致很多问题。我想也许重音人物首先没有被认出是一个案例,但经过一些测试我发现这不是问题,因为常规的无重音字母会出现同样的问题。我已经尝试添加考虑案例,但这不会使它工作。这是一个示例:
tell application "TextWrangler"
copy the contents of the selection of window 1 to meinText
set the contents of the selection of window 1 to asci2html(meinText) of me
end tell
on asci2html(derText)
considering case
tell application "TextWrangler"
set derText to replace "Á" using "Á" searchingString derText
set derText to replace "á" using "á" searchingString derText
set derText to replace "A" using "BIG" searchingString derText
set derText to replace "a" using "little" searchingString derText
return derText
end tell
end considering
end asci2html
那将测试重音字符以及字母'A',如果你在以下字符上运行它,你会看到它没有区分大小写:
一 一个 一个 A
有什么想法?感谢
答案 0 :(得分:0)
我想我解决了它,使用了一些我改编自macosxautomation.com的代码:
tell application "TextWrangler"
set outputText to "nuthing"
copy the contents of the selection of window 1 to meinText
set the contents of the selection of window 1 to asci2html(meinText) of me
return outputText
end tell
on replace_chars(this_text, search_string, replacement_string)
considering case
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end considering
end replace_chars
on asci2html(derText)
set the derText to replace_chars(derText, "a", "little")
set the derText to replace_chars(derText, "A", "BIG")
set outputText to derText
end asci2html
我确信它不是完全有效的:我在两个不同的变量之间蹦蹦跳跳的价值,以反复出现一些我无法想象的错误,但它似乎仍然有效,正如之前的截图!有什么想法吗?