Thursday, November 23, 2017

#1 2012-05-26 05:11:48 pm

Lithodora
Member
Registered: 2011-08-19
Posts: 22

Parsing paragraphs not working as it should be

I am pulling text from mail.app. The emails I am parsing have within them a list of dates (amongst other things):
Now I'm trying to get the dates into a list. No problem I thought...

Using the following methods did NOT work:

Using paragraphs did NOT work, returned the entire thing as a paragraph
set AppleScript's text item delimiters to (ASCII character 13) -- (Carriage Return)
set AppleScript's text item delimiters to (ASCII character 10) -- (LF)

Applescript:

set rundates to "5/27/2012
   5/28/2012
   5/29/2012
   5/30/2012
   5/31/2012
   6/1/2012
   6/3/2012
   6/4/2012
   6/5/2012
   6/6/2012
   6/7/2012
   6/8/2012
   6/10/2012
   6/11/2012"

set mylist to {}
repeat with z from 1 to count of characters of rundates
   if character z of rundates is not (ASCII character 202) then
       copy (ASCII number (character z of rundates)) to end of mylist
       ----set mylist to mylist & character z of rundates
   end if
end repeat

--return mylist ---{53, 47, 50, 55, 47, 50, 48, 49, 50, 13, 53, 47, 50, 56, 47, 50, 48, 49, 50, 13, 53, 47, 50, 57, 47, 50, 48, 49, 50, 13, 53, 47, 51, 48, 47, 50, 48, 49, 50, 13, 53, 47, 51, 49, 47, 50, 48, 49, 50, 13, 54, 47, 49, 47, 50, 48, 49, 50, 13, 54, 47, 51, 47, 50, 48, 49, 50, 13, 54, 47, 52, 47, 50, 48, 49, 50, 13, 54, 47, 53, 47, 50, 48, 49, 50, 13, 54, 47, 54, 47, 50, 48, 49, 50, 13, 54, 47, 55, 47, 50, 48, 49, 50, 13, 54, 47, 56, 47, 50, 48, 49, 50, 13, 54, 47, 49, 48, 47, 50, 48, 49, 50, 13, 54, 47, 49, 49, 47, 50, 48, 49, 50}


---===== Notice the 13s? So this should work right? ====---


set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to (ASCII character 13) -- (Carriage Return)
set runList to text items of rundates
set AppleScript's text item delimiters to tid
return runList --{"5/27/2012
   5/28/2012
   5/29/2012
   5/30/2012
   5/31/2012
   6/1/2012
   6/3/2012
   6/4/2012
   6/5/2012
   6/6/2012
   6/7/2012
   6/8/2012
   6/10/2012
   6/11/2012"}

Anyone have any ideas? What am I doing wrong here....

Offline

 

#2 2012-05-26 05:36:18 pm

Lithodora
Member
Registered: 2011-08-19
Posts: 22

Re: Parsing paragraphs not working as it should be

Applescript:

set mylist to ""
repeat with z from 1 to count of characters of rundates
   if character z of rundates is not (ASCII character 202) then
       if (ASCII number (character z of rundates)) is not 13 then
           set mylist to mylist & character z of rundates
       else
           set mylist to mylist & ","
       end if
   end if
end repeat


set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set runList to text items of mylist
set AppleScript's text item delimiters to tid
return runList

This worked... What a mess!

Offline

 

#3 2012-05-27 02:27:24 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Parsing paragraphs not working as it should be

Hi,

after copying the script in my script editor, aside from the alphanumeric characters there are only characters 160 (hex A0) and 8232 (hex 2028). This is a version using text item delimiters to remove the unwanted characters

Applescript:


set rundates to "5/27/2012
   5/28/2012
   5/29/2012
   5/30/2012
   5/31/2012
   6/1/2012
   6/3/2012
   6/4/2012
   6/5/2012
   6/6/2012
   6/7/2012
   6/8/2012
   6/10/2012
   6/11/2012"


set mylist to id of rundates
set {TID, text item delimiters} to {text item delimiters, ","}
set mylist to mylist as text
set mylist to removeCharacterFromText("160", mylist)
set mylist to removeCharacterFromText("8232", mylist)
set text item delimiters to TID

on removeCharacterFromText(theCharacter, theText)
   set {TID, text item delimiters} to {text item delimiters, ("," & theCharacter)}
   set theText to text items of theText
   set text item delimiters to ""
   set theText to theText as text
   set text item delimiters to TID
   return theText
end removeCharacterFromText


regards

Stefan

Offline

 

#4 2012-06-02 07:04:17 pm

Lithodora
Member
Registered: 2011-08-19
Posts: 22

Re: Parsing paragraphs not working as it should be

I was afraid that it would lose the formating issue I had when I pasted it on the the forums.

I did use your method because it looks cleaner and just subbed out the character codes that I really do get.
Part of me thinks the system they use to generate the numbers is running windows 95 or something.

Thanks for your help. Sadly I'm a Saturday programmer because it is the one day in my week I can spend writing code. No one else is here and during the week my bosses don't seem to understand that the scripts I write make me more productive. It just means it takes me a week to reply.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)