2011-11-02 6 views
1

5 개의 개체가있는 nsmutablearray가 있습니다.iphonesdk 문자열 추가 문제

예를 들어 사과, 고양이, 공, 개, 개미 같은 개체가 포함 된 경우 사과, 고양이, 공, 개, 개미와 같은 구분 된 쉼표로 추가 할 수 있습니다. 이걸 도와주세요.

편집

publishingpost //nsmutable array contains all these object 

-(ibaction)post 
{ 
nsstring *str; 
nsstring *str2 [email protected]","; 
for(int i = 0; i< [publishingpost count]; i++){ 
nsstring *str = [publishingpost objectAtIndex:i]; 
//append both str1, str2 to generate comma separated objects 

} 
+0

이 질문은, 파라 즈 다소 혼란이다. 질문을 분명히 할 수 있도록 단어를 다시 편집 할 수 있습니까? –

답변

4

사용 - (NSString *)componentsJoinedByString:(NSString *)separator :

- (IBAction)post { 
    NSString * str = [publishingpost componentsJoinedByString:@", "]; 
} 
0

것은 stringByAppendingString: 또는 here에서 stringByAppendingFormat를 살펴 보자. 이미 문자열이 있다면 쉽게 할 수 있어야합니다.

for 루프 앞에 NSString 객체를 선언하고 (또는 str을 사용) 루프를 통과하는 동안 NSString 객체를 추가하십시오. 그리고 코드에서 str을 두 번 선언하지 않아도됩니다. 그들 중 하나의 이름을 바꿀 수도 있습니다. 대신