使用規(guī)則
字符串需使用雙引號,不能使用單引號
字符串中有引號時(shí),需使用轉(zhuǎn)義字符"",如"\他說:"你好!""
字符串拼接--用&
set str to "hello world"
set str2 to "good morning "
set str3 to str2 & str
獲取字符串長度-- the length of
set num to the length of str3
字符串轉(zhuǎn)類型
set countStr to 100 as string
字符串切割
set str4 to "a-b-c-d-e"
方法1:獲取由每一個(gè)字符組成的數(shù)組
get every character of str4
方法2:按照指定的分隔符分割字符串
set oldDelimiters to AppleScript's text item delimiters --記錄開始的去限器
set AppleScript's text item delimiters to "-" --設(shè)置分隔符
set str4Arr to every text item of str4 -- 分割
set AppleScript's text item delimiters to oldDelimiters -- 恢復(fù)原來的去限器
get str4Arr --獲取數(shù)組
字符串的比較
begins with 或starts with ——以...開頭
does not start with ——不以。。。開頭
ends with ——以。。。結(jié)束
is equal to —— 相等
comes before —— 在。。。之前。比較兩字符的ascii碼
comes after ——在。。。之后。比較兩字符的ascii碼
is in —— 在。。。之中
is not in ——不在。。。中
contains ——包含
does not contain ——不包含