AppleScriptの文字列比較(2)〜considering, ignoring

AppleScriptの文字列比較で特徴的なのが、比較を行う場合に条件を設ける構文があるということです。それが、「考慮する」というconsideringと「無視する」というignoring。AppleScriptの基本構文として用意されており、1994年(一部には1993年に公開)の誕生以来、標準で用意されてきたものです。

このconsidering/ignoringでは、「大文字/小文字」(case)、「濁点/半濁点の有無」(diacriticals)、「ハイフンおよび全角スペース」(hyphens)、「ピリオドなどの記号」(punctuation)、「空白、改行文字、タブ」(white space)を指定。複数の条件を同時に宣言したり、consideringとignoringをネスティングさせて同時に使用することもできます。

スクリプト名:文字列比較2
set a to “abc”
set b to “C” –大文字にしてみた
set c to ” a b C “ –スペースを入れてみた

–大文字小文字を無視する
ignoring case
  if a is equal to b then
    display dialog “Equal 1″
  end if
end ignoring

–大文字小文字を考慮する
considering case
  if a is equal to b then
    display dialog “Equal 2″
  end if
end considering

–半角スペースを無視する
ignoring white space
  if a is equal to c then
    display dialog “Equal 3″
  end if
end ignoring

–半角スペースと大文字小文字を無視する
ignoring white space and case
  if a is equal to c then
    display dialog “Equal 4″
  end if
end ignoring

ignoring white space –半角スペースを無視する
  considering case –大文字小文字を考慮する
    if a is equal to c then
      display dialog “Equal 5″
    end if
  end considering
end ignoring

▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に

Leave a Reply