2017-06-04 7 views
0

テキストファイルをリストに読み込む簡単なコードがあります。これは、この形式のCMYK値のリストです:00, 100, 64, 33。何らかの理由で、出力がスペースを奇妙な文字で置き換えています... "¬†"(返信と短剣?)。Applescript:スペースを置き換える奇妙な文字( "¬†")

ので、このスクリプト:

set cmykList to {} 
set eachLine to paragraphs of (read POSIX file "/Users/me/Desktop/cmyk.txt") 
repeat with nextLine in eachLine 
    if length of nextLine is greater than 0 then 
     copy (nextLine as text) to the end of cmykList 
    end if 
end repeat 
choose from list cmykList 

リターン: 00,¬†100,¬†64,¬†33, 00,¬†00,¬†00,¬†00, 100,¬†72,¬†00, 100,¬†35,¬†00,¬†100

これは、なぜ上の任意のアイデア、そしてどのように私はこれを避けることができますか?

テキストファイルがそのようにように設定されています

00, 100, 64, 33 
00, 00, 00, 00 
100, 72, 00, 18 
100, 35, 00, 100 
00, 16, 100, 00 
00, 100, 63, 29 
00, 66, 100, 07 
03, 00, 00, 32 
100, 35, 00, 100 
00, 100, 81, 04 
04, 02, 00, 45 
00, 00, 00, 00 
03, 00, 00, 32 
100, 35, 00, 100 

編集:検索/置き換えをやって、この問題を解決しました:

set cmykList to {} 
set eachLine to paragraphs of (read POSIX file "/Users/me/Desktop/cmyk.txt") 
repeat with nextLine in eachLine 
    if length of nextLine is greater than 0 then 
     set theText to (nextLine as text) 
     set AppleScript's text item delimiters to " " 
     set theTextItems to text items of theText 
     set AppleScript's text item delimiters to " " 
     set theText to theTextItems as string 
     set AppleScript's text item delimiters to {""} 
     copy (theText as text) to the end of cmykList 
    end if 
end repeat 
set chooseList to choose from list cmykList 

しかし、まだこれが最初に起こった理由としては非常に好奇心場所。

答えて

0

これらの2文字(ASCII 194 160)は、Unicode NO-BREAK SPACE文字のUTF-8表現です。

テキストファイルのソースは指定しませんが、どこから来ているのかは通常のスペースの代わりに改行しないスペースを使用しています。あなたが知っているように、ファイルを読むときに通常のスペースに置き換えることで問題を解決できます。

0

ファイルには、UTF8エンコーディングのUnicodeテキストが含まれています。標準機能追加のreadwriteコマンド(愚かな)デフォルトでは、古代のクラシックMacOSの時代のレガシーエンコーディングを使用するので、あなたは明示的にUTF8を使用するように指示する必要があります:

set eachLine to paragraphs of (read POSIX file "/Users/me/Desktop/cmyk.txt" as «class utf8») 
関連する問題