Objective-C to ASOC ex2.

Here is 4 more examples from Objective-C to ASOC

use AppleScript version "2.4"
use framework "Foundation"

(** Objective-C
* NString *aString = @"hello";
* NString *anotherString = @"hello";
* BOOL stringAreEqual = ([aString isEqualToString:anotherString]);
*)

-- Correct String Comparison
set aString to current application's NSString's stringWithString:"hello"
set anotherString to current application's NSString's stringWithString:"hello"
set ex1 to aString's isEqualToString:anotherString --> true

(** Objective-C
* NString *aString = @"milk";
* NSMutableString *aMutableString = [NSMutableString stringWithString:@"Remember to buy apples"];
* [aMutableString appendString:@", orange juice"];
* [aMutableString appendFormat:@", and of course, %@", aString];
*)

-- Appending to NSMutableString
set aString to "milk"
set aMutableString to current application's NSMutableString's stringWithString:"Remember to buy apples"
aMutableString's appendString:", orange juice"
aMutableString's appendFormat:(", and of course, " & aString)
set ex2 to aMutableString as text --> "Remember to buy apples, orange juice, and of course, milk"

(** Objective-C
* NSMutableString *aMutableString = [NSMutableString stringWithString:@"abcdefghijk"];
* NSRange range = NSMakeRange(0, 4);
* [aMutableString deleteCharactersInRange:range];
*)

-- Deleting Characters with a Range
set aMutableString to current application's NSMutableString's stringWithString:"abcdefghijk"
set range to current application's NSMakeRange(0, 4)
aMutableString's deleteCharactersInRange:range
set ex3 to aMutableString as text --> "efghijk"

(** Objective-C
* NSString *aString = @" abcdefghijk";
* NSString *replacedString = [aString stringByReplacingOccurrencesOfString:@"ABC"
* 	withString:@"XYZ"
* 	options:NSCaseInsensitiveSearch
* 	range:NSMakeRange(0, aMutableString.length)];
*)

-- Replacing Characters with a Range
set aString to current application's NSString's stringWithString:"abcdefghijk"
set replacedString to (aString's stringByReplacingOccurrencesOfString:"ABC" withString:"XYZ" options:(current application's NSCaseInsensitiveSearch as integer) range:(current application's NSMakeRange(0, aString's |length|() as integer)))

set ex4 to replacedString as text --> "XYZdefghijk"

return {ex1, ex2, ex3, ex4}