我喜試圖將字符串轉換在Xcode爲int數組中目標C的運行良好,但給一些誤差在編輯http://ideone.com字符串int數組客觀
我有喜歡的輸入= {1,2,3,4 ,5},並希望將其轉換成int數組或NSArray的中和打印....
#import <Foundation/Foundation.h>
NSArray* sampleMethod(NSString*val){
NSString *stringWithoutbracketstart = [val stringByReplacingOccurrencesOfString:@"{" withString:@""];
NSString *stringWithoutbracketend = [stringWithoutbracketstart
stringByReplacingOccurrencesOfString:@"}" withString:@""];
NSLog(@"%@",stringWithoutbracketend);
NSArray *items=[[NSArray alloc]init];
items = [stringWithoutbracketend componentsSeparatedByString:@","];
//NSLog(@"%@",items);
return items;
}
int main(int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *value [email protected]"{1,2,3}";
NSArray* ip1= sampleMethod(value);
NSLog(@"%@",ip1);
[pool drain];
return 0;
}
這個例子在Java?中? – trojanfoe 2014-10-31 10:15:35
我很困惑爲什麼這個鏈接你提供了一些java代碼的鏈接,但你的問題是關於objective-c的問題? – Popeye 2014-10-31 10:17:22
@trojanfoe它屬於Objective C – 2014-10-31 10:20:49