2

CSVからデータを読み取るAppleScriptがあります(成功しました!)。スクリプトでデータの編集が完了したら、変更したテキストをそのファイルに書き戻します。 私のテキストがCSVファイルに書き戻されると、キャリッジリターンがすべて失われるため、1行として読み取られます。私は何が間違っているのですか?

set theFile to choose file with prompt "Select a text file:"
set theFileContents to read theFile
...


set theList to paragraphs of theFileContents



repeat with i from 2 to count theList

set AppleScript's text item delimiters to ","
set theLine to theList's item i
theLine
set clinic_id to first text item of theLine
....
set AppleScript's text item delimiters to ""

...

    open for access theFile with write permission

    set theData to theList as text
    write the [theData] to theFile as text
    close access theFile


    display dialog the [theLine]
end if
end repeat

助言がありますか?このコードの出力は次のとおりです。

1,2,3,A,B,C,X,Y,Z

私が欲しいのは

1,2,3
A,B,C
X,Y,Z
4

1 に答える 1

3

theListアイテムとして行(各行はコンマを含む文字列)を持っていると思いますので、のように見え{"1,2,3", "A,B,C", "X,Y,Z"}ますよね?したがって、ファイルに書き込むためにリストを a に変換するに、を改行文字に設定します。texttext item delimiters

set AppleScript's text item delimiters to "\n"
set theData to {"1,2,3", "A,B,C", "X,Y,Z"} as text

theData値を持つようになりました

"1,2,3
A,B,C
X,Y,Z"

これはまさに出力ファイルにあるものです。

于 2012-04-11T08:06:00.867 に答える