Javascript与Objective-C 字符串与数组的方法类比
String vs NSString
JavaScript string | Obj-C NSString |
---|---|
charAt(index) | (see text) |
charCodeAt(index) | - (unichar)characterAtIndex:(NSUInteger)index |
concat(string) | - (NSString *)stringByAppendingString:(NSString *)aString |
indexOf(string) | - (NSRange)rangeOfString:(NSString *)aString |
lastIndexOf(string) | - (NSRange)rangeOfString:(NSString *)aString options:NSBackwardsSearch |
localeCompare(string) | - (NSComparisonResult)localizedCompare:(NSString *)aString |
split(delimiter) | - (NSArray *)componentsSeparatedByString:(NSString *)separator |
substring(startIndex) | - (NSString *)substringWithRange:(NSRange)aRange |
toLowerCase() | - (NSString *)lowercaseString |
toUpperCase() | - (NSString *)uppercaseString |
Array vs NSArray
JavaScript Array | Obj-C NSArray |
---|---|
length | - (NSUInteger)count |
concat(item1[, item2...]) | - (NSArray *)arrayByAddingObject:(id)anObject -(NSArray *)arrayByAddingObjectsFromArray:(NSArray *)otherArray |
join(delimiter) | - (NSString *)componentsJoinedByString:(NSString *)separator |
sort() | - (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id, id, void |
toString() | - (NSString *)description |
摘自:Learning the iOS 4 SDK for JavaScript Programmers