Re: Wierd error
Re: Wierd error
- Subject: Re: Wierd error
- From: Paul Skinner <email@hidden>
- Date: Tue, 23 Sep 2003 08:23:27 -0400
Whoa. How about something a bit more direct?
my trim(" *%*&*!@#$^ |BLOW, JOE|* ^&*))&%^^%$ ")
-->"BLOW, JOE"
on trim(inputtext)
set valids to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a",
"b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
"R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
repeat with i from 1 to the length of characters of inputtext
if character i of inputtext is in valids then
set startValid to i
exit repeat
end if
end repeat
repeat with j from 1 to the length of characters of inputtext
if character (-j) of inputtext is in valids then
set endValid to j
exit repeat
end if
end repeat
set trimedText to text startValid thru (-endValid) of inputtext
end trim
PS
On Tuesday, September 23, 2003, at 01:15 AM, John Fowler wrote:
Dear sirs,
I download and parse pages and extract data from the pages using
AppleScript. My AppleScript application which does this has been
running fine and doing everything right for quite some time. Suddenly
a wierd error has cropped up in a well-established handler and I need
(several) fresh pairs of eyes to help me understand what could be
going on here.
Here is the handler that suddenly behaves wierdly:
on Trim(aString)
--trims non-character and non-numerics from beginning and end of a
string.
--leaves non-character and non-numerics unchanged in the middle of a
string
--requires "TrimTheStringList" and uses it for the front and back
ends of a string.
log "trimming |" & aString & "|"
set newString to ""
if length of aString is 0 then return newString
set currDelimiters to AppleScript's text item delimiters
log "currDelimiters: " & currDelimiters
set AppleScript's text item delimiters to ""
set theStringList to (every text item in aString)
log theStringList
set theStringList to (TrimTheStringList(theStringList))
set theStringList to the reverse of theStringList
set theStringList to (TrimTheStringList(theStringList))
set theStringList to the reverse of theStringList
repeat with anItem in theStringList
set newString to newString & anItem
end repeat
set AppleScript's text item delimiters to currDelimiters
return newString
end Trim
on TrimTheStringList(theStringList)
--display dialog theStringList as text
--trims everything but alpha and numeric characters
--corrected an error 3/17/2000 which deleted "a"
set TrimIt to true
log "TrimTheStringList with |" & theStringList & "|"
display dialog (AppleScript's text item delimiters)
repeat while TrimIt
if length of theStringList is 0 then
set TrimIt to false
else
if ((ASCII number of item 1 of theStringList) is greater than 64)
and ((ASCII number of item 1 of theStringList) is less than 91) then
set TrimIt to false
end if
if ((ASCII number of item 1 of theStringList) is greater than 96)
and ((ASCII number of item 1 of theStringList) is less than 123) then
set TrimIt to false
end if
if ((ASCII number of item 1 of theStringList) is greater than 47)
and ((ASCII number of item 1 of theStringList) is less than 58) then
set TrimIt to false
end if
end if
if TrimIt then
set theStringList to the rest of theStringList
end if
end repeat
return theStringList
end TrimTheStringList
The Trim handler calls TrimTheStringList but the error is in the Trim
handler.
Here is the relevant portion of the error log:
(*trimming |BLOW, JOE|*)
(*currDelimiters: *)
(*, , L, O, W, ,, , J, O, E*)
(*TrimTheStringList with |LOW, JOE|*)
display dialog ""
--> {button returned:"OK"}
ASCII number ""
--> Some parameter wasn't understood.
When the handler is called to parse out JOE BLOW's name from the web
page in question, it changes the first letter to "" when converting
the string to a string list. "Some parameter wasn't understood"
refers to the effort (in TrimTheStringList) to find the ASCII number
for character "", a null character.
Oddly, when I call the handler in a test scenario by just Trim("BLOW,
JOE"), it works fine. It only seems to omit the first letter in the
setting of the actual program. It doesn't just happen with "BLOW,
JOE" but with several other persons as well. (Actually Blow is fake).
As can be told from the error log as quoted, text item delimiters are
what I would expect them to be at the time of the error.
Between working (for the last year and more, impeccably) and not
working, the only interesting thing I can say happened was that I
tried my hand at perl last night on this computer, completely
unrelated to this application. I mention this only in case some deep
system setting may have been reset by perl, but I think otherwise this
is absurd as an explanation for what is going on. Even this is crazy,
since the program ran fine this morning and only started acting oddly
around mid-day when no programming or anything was going on. I run OS
X 10.2.8 on a PowerBook G4 with 1024 MB RAM.
I will be very grateful for any hints of what I can fix in this
scenario. I apologize for the long post.
John Fowler
_______________________________________________
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.
_______________________________________________
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.
References: | |
| >Wierd error (From: John Fowler <email@hidden>) |