• 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: Read a text file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Read a text file


  • Subject: Re: Read a text file
  • From: Christopher Stone <email@hidden>
  • Date: Tue, 29 Jul 2014 16:40:13 -0500

On Jul 29, 2014, at 14:25, Gil Dawson <email@hidden> wrote:
I have a sort of generic way of processing a plain text file line-by-line...
...
However, I'm running into problems:

1. Sometimes, the EOL delimiter is not return, but LF or CR/LF.
2. Sometimes, the encoding can be UTF-8, sometimes UTF-8 with BOM, sometimes UTF-16.

Is there a way for me to tell a priori what are the EOL delimiter and encoding for the file?
______________________________________________________________________

Hey Gil,

I'm with Stan.  Unless the file is massive I wouldn't read it line by line.

If I was dealing with different encodings I'd just use the Satimage.osax:

----------------------------------------------------------------------------
# Get the file selected in the Finder for testing.
tell application "Finder"
set fSel to selection as alias list
if fSel ≠ {} then
set file_ to first item of fSel
end if
end tell

# readtext (verb)read a text file. readtext is aware of the presence of BOM.
# (from the Satimage Text Additions suite, defined in Satimage.osax)

# ReadText:
set data_ to paragraphs of (readtext file_)

# OR find text:
set list_ to find text "^.+" in file_ with regexp, all occurrences and string result
----------------------------------------------------------------------------

Since the SIO is Unicode-aware the process should be transparent.

--
Best Regards,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Encrypt/Decrypt a Text File (From: Eric Geoffroy <email@hidden>)
 >Read a text file (From: Gil Dawson <email@hidden>)

  • Prev by Date: Re: Read a text file
  • Next by Date: Re: Weird behavior of text in Pages
  • Previous by thread: Re: Read a text file
  • Next by thread: Re: Read a text file
  • Index(es):
    • Date
    • Thread