Previous | Index | Next |
Offset vs Range methods
locationOfCharacterAt:inString:
These methods can be used to convert between AppleScript character indexes or offsets (which are based on composed character sequences) and NSRange values (which are based 16-bit unichar values). Range location and character index only differ when the text contains code points ouside Unicode's Basic Multilingual Plane.
Convert a character index from AppleScript to a Cocoa location or NSRange
+ (NSUInteger)locationOfCharacterAt:(NSNumber *)offset inString:(NSString *)aString
offset = AppleScript character index
aString = a string
An integer
Version 1.1.1
use scripting additions
use framework "Foundation"
use script "BridgePlus"
load framework
set aString to "A 😀 string."
set theResult to current application's SMSForder's locationOfCharacterAt:3 inString:aString
--> 2
set theResult to current application's SMSForder's locationOfCharacterAt:4 inString:aString
--> 4