• 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: replace text in chunks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: replace text in chunks


  • Subject: Re: replace text in chunks
  • From: Andy Wylie <email@hidden>
  • Date: Sun, 15 Dec 2002 14:31:54 +1300

on Sat, 14 Dec 2002 10:03:43 +1300 i wrote:

>you could store the new text and write it to the hosed file at the end of the
> loop but I don't know how that would work with large texts...

try this...

to |S+R Text File x 4025 hunk|(s, r)
try
set {oldDelims, sLength} to {AppleScript's text item delimiters,
count s}
set _file to (choose file with prompt "Choose a text file:")

chrono
set open_file to (open for access _file with write permission)
set {newText, _START, _END, |EOF|} to {{}, 1, 0, get eof of
open_file}

repeat until _END = |EOF|
set _END to _START + 4024
if _END > |EOF| then set _END to |EOF|
set hunk to read open_file from _START to _END
setTID(s)
set _List to hunk's text items
setTID(r)
set newText's end to _List as string
--[TMP]
if _START > 1 then
set _START to (_END - sLength)
else
set _START to _END
end if
setTID(oldDelims)
end repeat

set eof open_file to 0
write (newText as string) to open_file starting at 0
close access _file
setTID(oldDelims)
chrono
on error m number n
if n = -49 then
display dialog ({"\"", _file, "\"", " is in use"} as string)
close access _file
|S+R Text File x 4025 hunk|(s, r)
else
setTID(oldDelims)
if n is not -128 then error {n, m}
end if
end try
end |S+R Text File x 4025 hunk|


to setTID(x)
set AppleScript's text item delimiters to x
end setTID

--test
|S+R Text File x 4025 hunk|("Apple", "
Apple")


_____________________________ Andy
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Activating applications from a list
  • Next by Date: Re: Activating applications from a list
  • Previous by thread: Re: replace text in chunks
  • Next by thread: Re: replace text in chunks
  • Index(es):
    • Date
    • Thread