2017-02-15 13 views
0

HTMLのアクセント付き文字をスワップアウトするスクリプトがありますが、これはうまくいきますが、文字の大文字と小文字を区別しません。これは多くの問題を引き起こします。私はアクセント付きの文字が最初のケースとして認識されていなかったかもしれないと思ったが、いくつかのテストの後、同じ問題が通常のアクセントのない文字で発生するので、それは問題ではないことがわかった。私はケースを考慮して追加しようとしましたが、それは動作させません。AppleScriptで大文字と小文字が区別される

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 A Á

どのような考えですか?おかげ

+0

'consider/ignoring'は文字列の比較のみに影響します。この場合、効果はありません。 – vadian

+0

ありがとう、それは役立ちます。私は文字列の比較を行った別のバージョンも試しました(小文字のアルファベットを定義してから置換文字を選択する前に文字が入っているかどうかを確認しています)が、derText変数にはENTIRE文字列が含まれています私のアルファベットで)個々のキャラクターではなく、私はスクラブしています。このスクリプトでは、比較/置換するたびに発生する各文字を個別に実行する必要があるようです。どのようにそれを行う上の任意の簡単なポインターですか?ありがとう – buskerdog

+0

これは基本的に私が嘲笑したものですが、私が言ったように、derTextは個々のキャラクターではなく、私がスクラブしている選択全体です。どのように私はそれがその後、 \t \t \t \tセットderTextを置き換えるために、検出した各文字?: \t考える場合、小文字はderTextが含まれている場合に \t \t \t「ABCDEFGHIJKLMNOPQRSTUVWXYZ」 \t \t \t \t \t \tセット小文字のためにこれを実行することができます"少し"を使用して "小さい"を検索するderText \t \t \t else \t \t考える "BIG" searchingString derText \t \t \tエンド\t \t かの終わりを使用して "A" を交換する\tセットderText – buskerdog

答えて

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 

私はそれが完全に効率的ではないと確信しています:私は、異なる変数のカップルの間で値をバウンスしています私は理解できなかったいくつかのエラーをサイド・ステップで実行しましたが、それは前のスクリーンショットで見たように、とにかく動作しているようです!何かご意見は?

Screenshot-before-after

関連する問題