Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Convert end-of-line characters (AppleScript method)' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Convert end-of-line characters (AppleScript method)
Authored by: trekan on Oct 21, '03 05:05:28PM
You can also do this conversion in AppleScript. That is very practical if you're going to use files with foreign line endings in Applescripting.

In the following example we have just read the contents of a file and put it into fContents.

-- first we ask to put all the lines into a list (fParagraphs). AppleScript doesn't care if it is Unix, Mac or Windows.
set fParagraphs to paragraphs of fContents

-- now we tell AppleScript that lists will be concatenated using return characters when the list is converted to a string (Mac). This could also be "\n" for newline (UNIX), "\r\n" for character return+new line (Windows) or "\r" for character return (Mac). Don't be alarmed when you compile the script and see that \r and \n has changed into line breaks. The script still know that they are two different characters.
set AppleScript's text item delimiters to return

-- here we convert the list of paragraphs to strings using the text item delimiters
set fContentsNew to fParagraphs as string

-- here we reset the text item delimiters to "" which is default.
set AppleScript's text item delimiters to ""

[ Reply to This | # ]