• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Regex substitute/replace function in Applescript?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regex substitute/replace function in Applescript?


  • Subject: Re: Regex substitute/replace function in Applescript?
  • From: Graff <email@hidden>
  • Date: Sat, 09 Oct 2004 10:14:17 -0400

The easiest way to do this is the "paragraph" command and the text item delimiters
----
set theText to "some text" & return & "more text"
set pText to paragraphs of theText
set theDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ascii character 10
set newText to pText as text
set AppleScript's text item delimiters to theDelims
----


newText will contain a string with Unix line-endings.

The command "paragraphs" will split the text into a list which consists of each line (whether or not it has Mac, Unix, or Windows line endings). We then set the delimiter to LF (ascii character 10, the Unix new line) and coerce the list to a text string, which automatically puts the delimiter between the elements. You should always re-set the delimiter to what it was before (or to a blank string if it wasn't set before) so that subsequent operations aren't using the wrong delimiter by accident.

For a file just read a chunk of the file and do the trick above to each chunk.

- Ken

On Oct 9, 2004, at 9:40 AM, Randall Perry wrote:

What's the best way to do character replacement within a string (or file) in
Applescript? Is there a perl-like regular expression addon?


What I'm wanting to do is read the source of an Entourage email and save it
to a file, substituting the Mac eol character with Unix.

_______________________________________________ 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
  • Follow-Ups:
    • Re: Regex substitute/replace function in Applescript?
      • From: Randall Perry <email@hidden>
References: 
 >Regex substitute/replace function in Applescript? (From: Randall Perry <email@hidden>)

  • Prev by Date: Regex substitute/replace function in Applescript?
  • Next by Date: Re: Regex substitute/replace function in Applescript?
  • Previous by thread: Regex substitute/replace function in Applescript?
  • Next by thread: Re: Regex substitute/replace function in Applescript?
  • Index(es):
    • Date
    • Thread