Well, I got no response from my last post, but we’ll try this again.
I’ve got a search working to find a string "Stats " which in every case is followed by a number ranging from 0 to 99.
My first thought was to look at the second character after my search string to see if there was a non-numeral there or not. Problem is that the number following the search string is the last element in the line. All of these lines start with numbers, so if I look at the second character after the search string, it will always be a number.
So how do I solve this? Is there a way to look for a carriage return and line feed? I’m thinking not since I would have seen non=printing characters when I looked there and instead got the number from the following line.
What about grabbing the entire line that the result string is on and grabbing the last “word”? I don’t know how to phrase that. I’ve seen examples on how to choose a line, but not how to determine which line is to be choosen based on my result.
Or maybe there’s an easier way? Any help this time?
Your not giving us much to go by, but maybe this will work
get word 2 of "Stats 59"
-->59
It looks like there was a space after the word "Stats " but again it would help if there was more info. Second character will return the letter “t” as it is the second character in the word "Stats "
I take it you’re searching a text string here and not a document in an application. Lines [it]are[/it] separated by returns and/or line feeds, so those characters should have turned up when your search crossed the line boundaries.
The text chunks between returns are called paragraphs. You don’t say if "Stats " occurs in every line, but one approach would be to get a list of the text’s paragraphs:
set theParagraphs to paragraphs of theText
You could then check the end characters of each paragraph that contains "Stats ".
Another way, since each number is sandwiched between "Stats " and the end of the line, would be:
-- Break the text at each occurrence of "Stats "
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"Stats "}
set textItems to theText's text items
set AppleScript's text item delimiters to astid
-- Each 'text item' except the first starts with the end of a line -
-- a 'paragraph' containing only the required number text
repeat with i from 2 to (count textItems)
set numberStr to paragraph 1 of item i of textItems
-- Do something with the number text
end repeat
Sorry for not providing more! Here’s a snipped from the log file I am trying to parse…
The number after "Stats " (yes, there is a space after the last s), is what I want to capture in a variable. Multiple “Stats” appear in the file, but I am only concerned with the last one in the log. That number can be anything from 0-99. I don’t know what, but that’s why I need to capture it.
The second number I get when I try to read the 2nd place after the string is the “1” in the date on the following line, which is why I thought capturing a “line” would help in avoiding the wraparound. I guess I was hoping there was an easy way to get the “word” after my "Stats " string. Not sure of the syntax of this.
Thanks! If I’m still not giving you enough, please let me know!
set theText to "10/30/2003 00:05:07 {PEGHOGG} {ZCOGPGIBP} SignOn 80.142.176.119 "350211" "32Bit Windows" "SmilingDemon"
10/30/2003 00:05:07 - - Registering with Palace Directory service...
10/30/2003 00:05:07 - - Registration complete
10/30/2003 00:33:24 {PEGHOGG} {ZCOGPGIBP} SignOff 80.142.176.119 1 1697 "logged off"
10/30/2003 00:33:24 {PEGHOGG} {ZCOGPGIBP} Stats 1
10/30/2003 02:13:34 - - Registering with Palace Directory service...
10/30/2003 02:13:35 - - Registration complete
10/30/2003 02:28:15 - - Got TCP Connection!
10/30/2003 02:28:15 - - Sending TCP user ID [ 10H]
10/30/2003 02:28:15 - - Ready for TCP Connections"
if theText contains " Stats " then
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" Stats "}
set lastStatsValue to (first word of last text item of theText) as integer
set AppleScript's text item delimiters to astid
else
set lastStatsValue to false
end if
lastStatsValue
--> 1