index, AV, AppleScript, Bicycle, Cinema, DTM, Dairy, Dev, Fashion, Fitness, Game, Health, Help, Lyrics, Meal, Motor, Motorcycle, Music, Objective-C, PC, PDA, Phone, Robot, S15S, Stationary, Swift, Text, Travel, V36, Watch
--文字列WholeStrの中に文字列FStringが含まれているかどうか検索 --WholeStrの何文字目から何文字目までがFStringであるかを返します。 on FindString(FString, WholeStr) set FNum to (count characters of FString) set CurDelim to AppleScript's text item delimiters set AppleScript's text item delimiters to FString set StrList to text items of WholeStr set AppleScript's text item delimiters to CurDelim set WholeNum to (count items of StrList) - 1 set BufList to {} set CharNum to 1 set RepNum to 0 repeat with i in StrList set RepNum to RepNum + 1 if RepNum is WholeNum + 1 then exit repeat set StartNum to CharNum + (count characters of (i as string)) set EndNum to StartNum + FNum - 1 set BufList to BufList & {{StartNum, EndNum}} set CharNum to EndNum + 1 end repeat return BufList end FindString
--単純に、TargetStr中のpreをpostに置換して返します on FindAndReplace(pre, post, TargetStr) set CurDelim to AppleScript's text item delimiters set AppleScript's text item delimiters to pre set buf to text items of TargetStr set AppleScript's text item delimiters to post set buf to buf as string set AppleScript's text item delimiters to CurDelim return buf end FindAndReplace
--置き換えた数を返します。 --(検索文字列,置換文字列,対象文章) --{置換語の文章,置換数} on Exchanger(pre, post, target_str) set cur_delim to AppleScript's text item delimiters set AppleScript's text item delimiters to pre set buf_string to text items of target_str set ex_num to (count items of buf_string) - 1 set AppleScript's text item delimiters to post set buf_string to buf_string as string set AppleScript's text item delimiters to cur_delim return {buf_string, ex_num} end Exchanger