Re: Direct character replacement in a string
Re: Direct character replacement in a string
- Subject: Re: Direct character replacement in a string
- From: Jolly Roger <email@hidden>
- Date: Tue, 06 Feb 2001 20:03:05 -0600
- Replyto: email@hidden
on 2/6/2001 5:48 PM, FlyMac (email@hidden) wrote:
>
I get a string from a text file (using Akua) that could be something like
>
this:
>
"Th*s *s an ?xampl?"
>
Where every "*" should be replaced by an "i" and every "?" by an "e" before
>
doing something else in the script.
>
There is no problem to do this when the * are separated with a delimiter ("
>
" in this example) but when they are directly in a word ?
You can do this in vanilla Applescript easily:
-- begin script
set testStr to "Th*s *s an ?xampl?"
set testStr to SearchReplace(testStr, "*", "i")
set testStr to SearchReplace(testStr, "?", "e")
log testStr
on SearchReplace(sourceStr, searchString, replaceString)
set olddelis to AppleScript's text item delimiters
set AppleScript's text item delimiters to (searchString)
set theList to (every text item of sourceStr)
set AppleScript's text item delimiters to (replaceString)
set theString to theList as string
set AppleScript's text item delimiters to olddelis
return theString
end SearchReplace
-- end script
HTH
JR