Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > how does AppleScript interpret a line break?

how does AppleScript interpret a line break?
Thread Tools
schwa
Mac Enthusiast
Join Date: Oct 1999
Location: Brooklyn, NY, USA
Status: Offline
Reply With Quote
Jan 13, 2003, 01:09 PM
 
I have a script that is pulling events out of iCal and writing them to an LDIF text file. If an event has a note that contains a line break, that creates a problem for me, since LDIF expects a new line to contain a new name:value pair.

There are a couple ways I can deal with re-formatting the output, but I need some way for AppleScript to understand what a line break looks like. I don't think I can have it look based on ASCII values. Any ideas?

BTW, no, I can't do this via BBEdit. I want to be able to freely distribute the script as a stand-alone app.

TIA...
     
hayesk
Guest
Status:
Reply With Quote
Jan 13, 2003, 02:31 PM
 
There's a way to set a variable to ascii code 10 and ascii code 13 (cr and lf). Then, when working with strings you can have
mystring & cr & lf & mystring2

I'm not at my Mac now so I can't look 'em up for you, but search for AppleScript CGIs for web servers and they'll have some examples. That's where I found them.
     
schwa  (op)
Mac Enthusiast
Join Date: Oct 1999
Location: Brooklyn, NY, USA
Status: Offline
Reply With Quote
Jan 13, 2003, 05:15 PM
 
Thanks for the tip. I got it to work. Here's the code, if anyone's interested:

Code:
on CleanLineBreaks(dirty_string) set clean_string to "" set OldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to (ASCII character 10) set line_list to text items of dirty_string repeat with this_line in line_list set clean_string to clean_string & this_line if the length of line_list is greater than 1 then set clean_string to clean_string & ". " end if end repeat set AppleScript's text item delimiters to OldDelims return clean_string end CleanLineBreaks
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 08:52 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,