テキスト演算子
SenseTalkは、テキスト値の操作に特化したいくつかの演算子を含んでいます。
&
(アンパサンド) 演算子
Behavior: 値を一つずつ結合してテキスト文字列を作成します。両方のオペランドは、結合前に既にテキストでない場合、テキスト表現に変換されます。
構文:
operand1 & operand2
例:
put "The answer is:" & answer
&&
(ダブルアンパサンド) 演算子
Behavior: 二つの値をスペースを間に挟んで結合(連結)します。両方のオペランドは、結合前に既にテキストでない場合、テキスト表現に変換されます。
構文:
operand1 && operand2
例:
put "Dear" && correspondent & "," into openingLine
Is In
, Is Contained By
, Is Not In
, Isn't In
演算子
Behavior: 一つの値が他の値の中に存在するかどうかをテストし、真または偽を返します。
通常、この演算子は大文字と小文字を区別しません。大文字と小文字を区別するには、 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
演算子
Behavior: 一つの値が他の値の中に存在するかどうかをテストし、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
演算子
Behavior: 一つの値が他の値の中に全体としてのチャンク、リストアイテム、キー、または値として存在するかどうかをテストします。通常、この演算子は大文字と小文字を区別しません。大文字と小文字を区別するように強制するには、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
演算子
Behavior: テキスト文字列が特定の文字列で始まるかどうか、またはリストが特定の値または値のシーケンスで始まるかどうかを確認します。通常、この演算子は大文字と小文字を区別しません。大文字と小文字を区別するように強制するには、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
演算子
Behavior: テキスト文字列が特定の文字列で終わるかどうか、またはリストが特定の値または値のシーケンスで終わるかどうかを確認します。通常、この演算子は大文字と小文字を区別しません。大文字と小文字を区別するように強制するには、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 ...