メインコンテンツまでスキップ

テキスト演算子

SenseTalkは、テキスト値の操作に特化したいくつかの演算子を含んでいます。

& (アンパサンド) 演算子

振る舞い: 値を一つずつ結合してテキスト文字列を作成します。両方のオペランドは、結合前に既にテキストでない場合、テキスト表現に変換されます。

構文:
operand1 & operand2

例:

put "The answer is:" & answer

&& (ダブルアンパサンド) 演算子

振る舞い: 二つの値をスペースを間に挟んで結合(連結)します。両方のオペランドは、結合前に既にテキストでない場合、テキスト表現に変換されます。

構文:
operand1 && operand2

例:

put "Dear" && correspondent & "," into openingLine

Is In, Is Contained By, Is Not In, Isn't In 演算子

振る舞い: 一つの値が他の値の中に存在するかどうかをテストし、真または偽を返します。

通常、この演算子は大文字と小文字を区別しません。大文字と小文字を区別するには、 considering case オプションを使用します。

構文:
targetValue is {not} in sourceValue {considering case | ignoring case}
targetValue is {not} contained by sourceValue {considering case | ignoring case}

_sourceValue_がリストの場合、この演算子はその値のいずれかが_targetValue_と等しいかどうかをテストします。_targetValue_もリストの場合、_sourceValue_の値の連続するシーケンスが_targetValue_の値と等しいかどうかをテストします。

_sourceValue_が範囲の場合、それはリストと同じように扱われ(範囲をリストに変換することによって生成されるリストと同様)、そのリストの値が_targetValue_の存在をチェックします。これは is within演算子とは異なり、値が範囲の開始値と終了値の間のどこかにあるかどうかをチェックします。

_sourceValue_がプロパティリスト(オブジェクト)の場合、その振る舞いはオブジェクト自体、または組み込みの containsItem 関数によって決定されることができます(詳細はオブジェクトの内容の確認を参照してください)。

_targetValue_がSenseTalkのパターン言語を使用して定義されたパターンの場合、この演算子はパターンが_sourceValue_の中の任意の部分文字列にマッチするかどうかをテストします。

それ以外の場合、_sourceValue_はテキストとして評価され、それが_targetValue_を部分文字列として含むかどうかをテストします。sourceValueがリストまたはプロパティリストの場合に部分文字列テキスト検索を強制するには、 asText 関数または as text 演算子を使用してそれをテキストに変換します。

例:

if "--help" is in commandLine then ...

例:

if "Johnson" is not in indexList then ...

例:

put 12 is in [[11,12],[13,14]] -- True

例:

put [2,3] is in [1,2,3,4,5] -- True

例:

put [2,3] is contained by 1..5 -- True

例:

put <"(", chars,")"> is in "Elvis (the King) Presley" -- True

Contains, Does Not Contain, Doesn't Contain 演算子

動作: 一つの値が他の値の中に存在するかどうかをテストし、trueまたはfalseを返します。通常、この演算子は大文字と小文字を区別しません。大文字と小文字を区別するように強制するには、 considering case オプションを使用します。これは is in 演算子と全く同じ操作を行いますが、関係性を逆に表現することができます。与えられた文脈で自然に感じる方を使用してください。

構文:
sourceValue contains targetValue {considering case | ignoring case}
sourceValue does {not} contain targetValue {considering case | ignoring case}

_sourceValue_がリストの場合、この演算子はその値のいずれかが_targetValue_に等しいかどうかをテストします。_targetValue_もリストの場合、_sourceValue_の値の連続するシーケンスが_targetValue_の値に等しいかどうかをテストします。

_sourceValue_が範囲の場合、リストと同じように扱われます(範囲をリストに変換することによって生成される)そのリストの値が_targetValue_の存在をチェックします。これは is within 演算子とは異なり、値が範囲の開始値と終了値の間のどこかにあるかどうかをチェックします。

_sourceValue_がプロパティリスト(オブジェクト)の場合、その振る舞いはオブジェクト自体、または組み込みの containsItem 関数によって決定されることができます(詳細はオブジェクトの内容の確認を参照してください)。

それ以外の場合、_sourceValue_はテキストとして評価され、それが_targetValue_を部分文字列として含むかどうかをテストします。sourceValueがリストまたはプロパティリストの場合に部分文字列テキスト検索を強制するには、 asText 関数または as text 演算子を使用してそれをテキストに変換します。

例:

if commandLine contains " -x " considering case then ...

例:

if word n of partNums doesn't contain "q" then ...

例:

put nameList contains "Mayfield" into shouldInvite

例:

put 5..17 by 2 contains 8 -- false, since only odd numbers are generated

例:

put ["abcd","defg"] contains "abc" -- false

例:

put ["abcd","defg"].asText contains "abc" -- true

Is Among, Is Not Among, Isn't Among 演算子

動作: 一つの値が他の値の中に全体としてのチャンク、リストアイテム、キー、または値として存在するかどうかをテストします。通常、この演算子は大文字と小文字を区別しません。大文字と小文字を区別するように強制するには、considering case オプションを使用します。 ChunkTypes は文字、文字、単語、行、アイテム、テキストアイテム、リストアイテム、キー、値、またはバイトのいずれかになる可能性があります。

構文:
targetValue is {not} among {the} chunkTypes of sourceValue {considering case | ignoring case}

例:

put "cat" is among the items of "dog,cat,mouse" -- True

例:

put "be" is not among the words of "bell jibe amber" -- True

例:

if "cost" isn't among the keys of part then set part's cost to 10

Begins With, Does Not Begin With, Doesn't Begin With 演算子

動作: テキスト文字列が特定の文字列で始まるかどうか、またはリストが特定の値または値のシーケンスで始まるかどうかを確認します。通常、この演算子は大文字と小文字を区別しません。大文字と小文字を区別するように強制するには、considering case オプションを使用します。

構文:
operand1 begins with operand2 {considering case | ignoring case}
operand1 does {not} begin with operand2 {considering case | ignoring case}

例:

if sentence begins with "Joshua " considering case then ...

例:

if word n of productNames does not begin with "q" then ...

例:

if [9,12,14,23] begins with [9,12] then put "yes" -- yes

Ends With, Does Not End With, Doesn't End With 演算子

動作: テキスト文字列が特定の文字列で終わるかどうか、またはリストが特定の値または値のシーケンスで終わるかどうかを確認します。通常、この演算子は大文字と小文字を区別しません。大文字と小文字を区別するように強制するには、considering case オプションを使用します。

構文:
operand1 ends with operand2 {considering case | ignoring case}
operand1 does {not} end with operand2 {considering case | ignoring case}

例:

if sentence ends with "?" then ...

例:

if word n of plurals does not end with "es" then ...

例:

if scoresList ends with [98,99,100] then resetScores

例:

put "size 13W" ends with <2 digits then a letter> -- True

Matches, Does Not Match, Doesn't Match 演算子

動作: matches 演算子を使用して、変数または式がパターンと完全に一致するかどうかをテストします。オペランドの一方はパターンであり、もう一方は文字列値として扱われます。パターンが文字列全体と完全に一致する場合、この演算子は true を返します。パターンが文字列の一部のみに一致する場合や一致しない場合、matches 演算子の結果は false です。

matches 演算子は、パターンが全値に潜在的に一致する可能性がある場合は true を返し、デフォルトで使用される怠惰な量子化子のためにパターンの通常の一致が全文字列を返さない場合でもです。

SenseTalk のパターン言語についての詳細は、SenseTalk Pattern Language Basicsを参照してください。

構文:
operand1 matches operand2
operand1 [doesn’t | does not] match operand2

例:

put 83 matches <digit,digit> --> True

例:

put <"x", 3 chars, "y"> matches "xyzzy" --> True

例:

put <"$", digits> matches "$895" --> True
put the occurrence of <"$", digits> in "$895" --> "$8"

例:

set partNum to <"ABC", digit, char in "JQXZ", digit>
put partNum matches "Abc9Q2" --> True ("ABC" is not case sensitive)
put partNum matches "Abc9Q2" with case --> False ("ABC" must match case)