• 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: Comparing for case difference
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing for case difference


  • Subject: Re: Comparing for case difference
  • From: "Marc S.A. Glasgow" <email@hidden>
  • Date: Wed, 18 Dec 2002 22:18:52 -0500

Do you actually need the offset, or just to compare if both strings are the same except for the capitalization?
The fastest way I've found is still BBEdit (or BBEdit lite), if the files are in text form; the program will return the offset of differences between two files. If you are concerned about differences other than capitalization, then use the set case command to change all the text to either upper or lower.

Within AppleScript, a simple way to make it (somewhat) faster would be to do a raw comparison of both strings in an equals statement before cycling through the letters (thus skipping the cycling if they are the same).

if (a as text) = (b as text) then
-- the same
else
-- cycle
end if

Best Wishes,
=-= Marc Glasgow

On Wednesday, December 18, 2002, at 07:38 PM, email@hidden wrote:

Message: 10
Date: Wed, 18 Dec 2002 13:58:46 -0600
Subject: Comparing for case difference
From: Laine Lee <email@hidden>
To: Applescript Users <email@hidden>

I have this script that checks for case difference between two strings, but
if the strings are very long, this can really eat up time.

Can you give me something better for comparing long strings for case
difference? Thanks.

set a to "jeremiah"
set b to "jeremiaH"

Checkchange(a, b)

on Checkchange(x_string, y_string)
set mychanged to false
repeat with this_char in x_string
set myitem to (offset of this_char in y_string)
try
get (item myitem of y_string)
on error
set mychanged to true
exit repeat
end try
end repeat
if not mychanged then
display dialog "Same!" buttons {"OK"} default button 1
else
display dialog "Different!" buttons {"OK"} default button 1
end if
end Checkchange

--
Laine Lee
email@hidden
http://www.txdirect.net/users/llee
_______________________________________________
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.

  • Prev by Date: Project: iRanking
  • Next by Date: Re: Monitor Folder For Changes
  • Previous by thread: Re: Comparing for case difference
  • Next by thread: Monitor Folder For Changes
  • Index(es):
    • Date
    • Thread