2017-10-08 5 views
0

「A & B」のような文字列の単語をAppleScriptに数えると、テキスト項目の区切り文字がスペースに設定されていると、2が返されます。アンパサンドは単語としてカウントされません。それを変える方法はありますか?結局、 "&"は "and"を意味し、それは単語として数えられます。Applescriptを単語としてカウントする方法はありますか?

答えて

0

はここに回避策です:この例では

set theString to "A & B" 
set wordCount to do shell script "wc -w <<< " & quoted form of theString & " | tr -d ' '" 

、それが返されます:3

0

このスクリプトは、あなたのフォルダ/Library/ScriptingAdditions/Satimage.osaxにSatimage.osaxファイルを入れた後Satimage.osax scripting addition.を使用しています、メニュー項目に移動して、「ウィンドウ/ライブラリを」その辞書とScriptEditor.appでのすべてのコマンドを表示することができるはず

Download Satimage Scripting Addition

set theString to "A & B" 
set toExclude to {" "} as list -- Variable For Items To Be Removed From Your List In Line 4 

set theWordCount to items of theString -- Returns The Items Of Your String As A List {"A", " ", "&", " ", "B"} 

set resultList to exclude items toExclude from theWordCount -- Removes Specified Items From The List 
set theWordCount to count items of resultList -- Returns 3 As Your Count 

get theWordCount -- This Line Is Not Necessary And Can Be Removed 
関連する問題