• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Total Newbie question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Total Newbie question


  • Subject: Re: Total Newbie question
  • From: Hugh Dixon <email@hidden>
  • Date: Fri, 15 Jun 2001 08:33:17 +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 clean_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):


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 mainString to clean_stuff
set searchString to " " & tab
set replaceString to tab
set formatted_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
**********************************************************************


References: 
 >Total Newbie question (From: "roblef" <email@hidden>)

  • Prev by Date: Re:Eliminating items from a MS Word list
  • Next by Date: ImageMagick and RGB Colours
  • Previous by thread: Total Newbie question
  • Next by thread: Re: Total Newbie question
  • Index(es):
    • Date
    • Thread