• 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: String replacement
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String replacement


  • Subject: Re: String replacement
  • From: Timothy Bates <email@hidden>
  • Date: Tue, 09 Apr 2002 14:29:17 +1000

On 9/4/02 1:49 PM, "Matthew Stuckwisch" <email@hidden> wrote:

>> "i" and "I" as search strings
>
> Scratch the search string part. Since I'm planning on making it
> localizable for other languages (and AS won't return true for conditions
> like "a" = "a"),
Don't know what you mean. On my machine
"a" = "a"
-->true

> same setup, except have a single search string with
> multiple letters, for example, instead of search for "i" and "I" (which I
> now realize AS recognizes "I" and "i" as the same),

Just do your comparison inside a "considering" statement
"A" = "a"
-->true

considering case
"A" = "a"
-->false
end considering

>search for any letter in "imlon".
> Thanks for any help anyone's able to give.

This will do it

set thetarget to "this is your life"
set thetarget to characters of thetarget
set hangmanstring to {}
repeat with N from 1 to count of thetarget
set end of hangmanstring to ""
end repeat

(* set aletter to "a"
set x to getOffset(aletter, thetarget)
return {x, aletter, thetarget}
*)
set p to 0
repeat with aletter in {" ", "a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x",
"y", "z"}
set offsetList to getEveryOffset(contents of aletter, thetarget)
if offsetList is -1 then
exit repeat
else
repeat with x in offsetList
set item x of hangmanstring to aletter as string
end repeat
end if
end repeat


return hangmanstring

on getEveryOffset(what, TheList)
set offsetList to {}
script -- a trick to speed up list access
property _theList : TheList
end script
tell result
repeat with N from 1 to TheList's length
if (item N of its _theList) = what then set end of offsetList to
N
end repeat
return offsetList
end tell
return -1 --not found
end getEveryOffset
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: String replacement (From: Matthew Stuckwisch <email@hidden>)

  • Prev by Date: Re: String replacement
  • Next by Date: Re: Activating applet or app?
  • Previous by thread: Re: String replacement
  • Next by thread: Re: Finder Version Wrong in OS X
  • Index(es):
    • Date
    • Thread