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
*))comparator context:(void *)context

toString() - (NSString *)description

 

摘自:Learning the iOS 4 SDK for JavaScript Programmers  

 PDF下载>>

上一篇:what a fuck!这是什么鬼东西?——实验吧


下一篇:《指针的编程艺术(第二版)》一2.2 两颗星星:表示两把钥匙