• 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: Finding \t, \r, \n reliably
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding \t, \r, \n reliably


  • Subject: Re: Finding \t, \r, \n reliably
  • From: Christopher Nebel <email@hidden>
  • Date: Fri, 21 Oct 2005 14:45:23 -0700

On Oct 21, 2005, at 2:26 PM, Grimm, Kenneth wrote:

I'm perplexed. I have a text file I read into a variable, and if the ending of the file ends with \t\r\n I want to take those off.

When in Script Debugger, I can type the "\n" in the if statement, compiles to its invisible representation, and it finds the character just fine. However, on subsequent runs (the text file read doesn't change at all) it never finds the character! I hand- type it in again, compile, and then it's OK, until the next run.

I'd guess that if you merely run the script twice in a row, it works both times, but if you run, edit, recompile, and then run, it breaks? Differences in text-editing engines cause the "\n" and "\r" sequences to not work reliably -- which one breaks depends on the editor. Essentially, what happens is that you type "\n", the editor compiles it, gets a literal linefeed back from the decompilation, and then the engine says "oo, I don't really do LFs, I'll just change that to a CR", and poof, your script has changed.


The solution is to use "ASCII character 10" (13 for a CR) instead of the string "\n". (It's best to put that in a variable; calling "ASCII character" repeatedly can get expensive.) We've discussed making AppleScript decompile CR and LF as the "\r" or "\n" sequence, but the general consensus is that this would annoy more people than it helps, because a lot of people like typing multi-line string constants and seeing them as multiple lines.


--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


  • Follow-Ups:
    • Re: Finding \t, \r, \n reliably
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Finding \t, \r, \n reliably (From: "Grimm, Kenneth" <email@hidden>)

  • Prev by Date: Finding \t, \r, \n reliably
  • Next by Date: Re: Finding \t, \r, \n reliably
  • Previous by thread: Finding \t, \r, \n reliably
  • Next by thread: Re: Finding \t, \r, \n reliably
  • Index(es):
    • Date
    • Thread