• 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: Direct character replacement in a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Direct character replacement in a string (From: FlyMac <email@hidden>)

  • Prev by Date: How to set Startup disk in OS 8.1 & 8.0
  • Next by Date: Re: run-only
  • Previous by thread: Re: Direct character replacement in a string
  • Next by thread: Re: Direct character replacement in a string
  • Index(es):
    • Date
    • Thread