Re: Total Newbie question
Re: Total Newbie question
- Subject: Re: Total Newbie question
- From: Hugh Dixon <email@hidden>
- Date: Fri, 15 Jun 2001 12:18:20 +0000
On 14/6/01 4:25 pm, roblef wrote
>
I'm looking for a way to clean up text files, from form submissions on the
>
web. With a simple form, we get something like the following:
>
>
name=joe
>
date=january
>
comment=I hate forms
>
>
I'd like to be able to reformat this stuff, either into a spreadsheet or
>
table format, possibly several submissions in a document. Take the <category
>
=xxxxx> out of it altogether. Is this possible with Applescript?
Hi
How about
set dirty_stuff to "name=joe
date=january
comment=I hate forms"
on clean_up (any_stuff)
set {oldtids, newtids} to {AppleScript's text item delimiters, "="}
set AppleScript's text item delimiters to newtids
set formatted_stuff to ""
repeat with x from 1 to count paragraphs in any_stuff
set formatted_stuff to formatted_stuff & text item 2 of paragraph x of
any_stuff & tab
end repeat
set AppleScript's text item delimiters to oldtids
return formatted_stuff
end clean_up
set cleaner_stuff to clean_up (dirty_stuff)
You can clean up the loose spaces at the end of each paragraph with a search
and replace routine (which I would credit if I could remember who I copied
it from):
set mainString to cleaner_stuff
set searchString to " " & tab
set replaceString to tab
on SearchReplace(mainString, searchString, replaceString)
considering case
set olddelis to AppleScript's text item delimiters
set AppleScript's text item delimiters to (searchString)
set theList to (every text item of mainString)
set AppleScript's text item delimiters to (replaceString)
set theString to theList as string
set AppleScript's text item delimiters to olddelis
end considering
return theString
end SearchReplace
set clean_stuff to SearchReplace(mainString, searchString, replaceString)
Hope this helps.
Hugh
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
www.mimesweeper.com
**********************************************************************