Re: Continuation marks in strings
Re: Continuation marks in strings
- Subject: Re: Continuation marks in strings
- From: Christopher Nebel <email@hidden>
- Date: Sun, 7 May 2006 16:53:04 -0700
On May 4, 2006, at 7:53 AM, Monte Babington wrote:
Once I parse data out of source retrieved from Safari, I get a
string with
line breaks in it!
When I put the source in BBEdit with the invisibles turned on, what
do I
find? A couple of continuation marks.
For some reason Applescript preserves the carriage returns that the
continuation marks were placed to remove.
Those aren't continuation marks, at least not in the sense that
AppleScript uses them -- that's how BBEdit shows a line break when
you have invisibles turned on. Those line breaks were there in the
original source; AppleScript didn't add anything.
Does anyone know of a way to remove carriage returns from within a
string?
There are at least two. The usual way to do search-and-replace in
vanilla AppleScript (that is, no third-party tools) is to use "text
item delimiters":
set AppleScript's text item delimiters to return -- the search string.
set intermediateString to every text item of myString
set AppleScript's text item delimiters to " " -- the replace string;
set this to "" if you want to delete them.
set newString to intermediateString as string
Since you know you're going for line breaks (which, by the way, may
not be carriage returns), you could do this instead:
set AppleScript's text item delimiters to " "
set newString to (get every paragraph of myString) as string
This is slightly different than the first, since it replaces any
style of line break: CR, LF, or CRLF.
--Chris Nebel
AppleScript and Automator Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden