• 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: Reverse Offset (was Getting the Folder name when using drag-&-drop Scripts)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reverse Offset (was Getting the Folder name when using drag-&-drop Scripts)


  • Subject: Re: Reverse Offset (was Getting the Folder name when using drag-&-drop Scripts)
  • From: jj <email@hidden>
  • Date: Thu, 11 Mar 2004 10:27:16 +0100

> At 03:53p -0700 03/10/2004, Easthope, John R didst inscribe upon an
> electronic papyrus:
>
>> * File
>> copy (choose file) as string to thePath
>> copy text (((length of thePath) + 2) - ((offset of ":" in (reverse
>> of characters of thePath) as string))) thru (length of thePath) of
>> thePath to filename
>
> Hey, I like that 'reverse' method. Now I've made a nice routine:
>
> on ReverseOffset(ftxt, wtxt)
> local ftxt, wtxt, ftxt_r, wtxt_r, o_r
> set ftxt_r to (reverse of characters in ftxt) as string
> set wtxt_r to (reverse of characters in wtxt) as string
> set o_r to (offset of ftxt_r in wtxt_r as string)
> if o_r is 0 then return 0
> 2 + (length of wtxt) - o_r - (length of ftxt)
> end ReverseOffset
>
> Only briefly tested just now, but seems to do right.
>
>
> -boo

Though now, in Panther, your routine will fail:

ReverseOffset("Hello", "Hello, hello") --> 8, instead of 1
on ReverseOffset(ftxt, wtxt)
local ftxt, wtxt, ftxt_r, wtxt_r, o_r
set ftxt_r to (reverse of characters in ftxt) as string
set wtxt_r to (reverse of characters in wtxt) as string
set o_r to (offset of ftxt_r in wtxt_r as string)
if o_r is 0 then return 0
2 + (length of wtxt) - o_r - (length of ftxt)
end ReverseOffset

You need now the "considering case" statement for "offset of":

reverseOffset2("Hello, hello", "Hello") --> -12
to reverseOffset2(t, s)
considering case
if t does not contain s then return 0
-(offset of ("" & reverse of s's items) in ("" & reverse of t's
items)) - (count s) + 1
end considering
end reverseOffset2

jj

--
http://www.macscripter.net/
http://www.osaxen.com/
_______________________________________________
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.


  • Follow-Ups:
    • Re: Reverse Offset (was Getting the Folder name when using drag-&-drop Scripts)
      • From: Christopher Nebel <email@hidden>
  • Prev by Date: Re: do visual basic
  • Next by Date: Date object into FMP field
  • Previous by thread: Reverse Offset (was Getting the Folder name when using drag-&-drop Scripts)
  • Next by thread: Re: Reverse Offset (was Getting the Folder name when using drag-&-drop Scripts)
  • Index(es):
    • Date
    • Thread