Re: Snarfing Text between Variables
Re: Snarfing Text between Variables
- Subject: Re: Snarfing Text between Variables
- From: Motoyuki Tanaka <email@hidden>
- Date: Sun, 11 Mar 2001 00:37:26 +0900
At 08:40 -0500 03/09/2001, Xandra Lee wrote:
>
2. 3rd party OSAXen OK
>
2. Once text is isolated, I'll do some parsing on that text, then replace
>
it with parsed version.
Using "MT Pick strings" in Tanaka's osax 2.0, the following script does
what you want.
set myData to "YadaYadayYada
TS1
Tanaka
TS2
YadaYadayYada
YadaYadayYada
TS1
Motoyuki
TS2
YadaYadayYada"
myParser(myData)
--> "YadaYadayYada
TS1
tANAKA
TS2
YadaYadayYada
YadaYadayYada
TS1
mOTOYUKI
TS2
YadaYadayYada"
--- Script ---
on myParser(myText)
set tStr1 to "TS1" & return
set tStr2 to return & "TS2"
set xL to MT Pick Strings myText start with tStr1 end with tStr2 with trimming
repeat with thisItem in xL
-- parsing
set newItem to revCase(thisItem)
-- replacing
set myText to MT Replace myText search (tStr1 & thisItem & tStr2) replace (tStr1 & newItem & tStr2) with only first hit
end repeat
end myParser
on revCase(myText)
set myText to characters of myText
repeat with thisChar in myText
set x to ASCII number thisChar
if x > 96 then
set x to x - 32
else
set x to x + 32
end if
set contents of thisChar to ASCII character x
end repeat
return myText as string
end revCase
Hope this helps.
==============================================================
Motoyuki Tanaka Fukui Prefectural University
email@hidden Faculty of Economics
http://mtlab.ecn.fpu.ac.jp/