Previous | Index | Next |
Offset vs Range methods
rangeOfCharacterAt: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. Gets the string range from a character index.
+ (NSRange)rangeOfCharacterAt:(NSNumber *)offset inString:(NSString *)aString
offset = AppleScript character index
aString = a string
A range record
Version 1.0.0
use scripting additions
use framework "Foundation"
use script "BridgePlus"
load framework
set aString to "A 😀 string."
set theResult to current application's SMSForder's rangeOfCharacterAt:3 inString:aString
--> {location:2, length:2}
set theResult to current application's SMSForder's rangeOfCharacterAt:4 inString:aString
--> {location:4, length:1}