Re: Using AppleScript to Detect Nul Characters
Re: Using AppleScript to Detect Nul Characters
- Subject: Re: Using AppleScript to Detect Nul Characters
- From: kai <email@hidden>
- Date: Sat, 30 Apr 2005 20:00:33 +0100
On Saturday, April 30, 2005, at 06:01 pm, Bernardo Hoehl wrote:
Thanks Gnarlie, Jean-Baptiste and Kai,
I have come up with this simple script, using your tips:
(didn't know I could simply reffer to the Nul chars as ASCII character
0)
set thefile to (read (choose file))
set thelist to every character of thefile
repeat with i from 1 to the count of thelist
if text i of thelist is (ASCII character 0) then
beep
display dialog "Found an invalid character on position " & (i as
text)
end if
end repeat
Just one final observation, Bernardo.
There are faster ways of checking for the position of a character in
text, rather than iterating through every character. The handler below,
for example, should be pretty nippy - and also checks for multiple
occurrences of a character:
------------
to checkText from t for c
set l to {}
set d to text item delimiters
set text item delimiters to c
if (count t's text items) > 1 then
set p to 0
repeat with i in t's text items 1 thru -2
set p to p + 1 + (count i)
set l's end to p
end repeat
set text item delimiters to ", "
set l to "Invalid character at position " & l & "."
end if
set text item delimiters to d
if (count l) > 0 then display dialog l
end checkText
set theFile to read (choose file)
checkText from theFile for ASCII character 0
------------
---
kai
_______________________________________________
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