NSMutableArray를 문자열로 바꾸는 방법을 찾고 있습니다. 이 Ruby 배열 방법과 비슷한 점이 있습니까?Objective-C의 배열에 가입하십시오.
>> array1 = [1, 2, 3]
>> array1.join(',')
=> "1,2,3"
건배!
NSMutableArray를 문자열로 바꾸는 방법을 찾고 있습니다. 이 Ruby 배열 방법과 비슷한 점이 있습니까?Objective-C의 배열에 가입하십시오.
>> array1 = [1, 2, 3]
>> array1.join(',')
=> "1,2,3"
건배!
NSArray *array1 = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
NSString *joinedString = [array1 componentsJoinedByString:@","];
componentsJoinedByString:
지정된 문자열 배열의 요소를 결합하고 상기 어레이의 문자열 표시를 리턴한다.
찾고있는 방법은 componentsJoinedByString
입니다.
NSArray *a = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];//returns a pointer to NSArray
NSString *b = [a componentsJoinedByString:@","];//returns a pointer to NSString
NSLog(@"%@", b); // Will output 1,2,3
NSArray *pathArray = [NSArray arrayWithObjects:@"here",
@"be", @"dragons", nil];
NSLog(@"%@",
[pathArray componentsJoinedByString:@" "]);