2016-09-02 1 views

답변

1

@로 시작하는 단어 배열을 가져옵니다. 배열의 단어 색인은 문자열의 색인입니다.

NSString *str = @"Hello world. How @are you ? Hope that @you are @doing well. Can you @please suggest me?"; 
NSMutableArray *atWordArray = [[NSMutableArray alloc] init]; 
NSArray *arrAllStr = [str componentsSeparatedByString:@" "]; 

for (NSString *individualString in arrAllStr) { 
    if ([individualString hasPrefix:@"@"]) { 
     [atWordArray addObject:individualString]; 
    } 
} 

NSLog(@"There are %d word/s in string they are /n",atWordArray.count,atWordArray); 
0
당신은 같이 할 수

,

NSString *str = @"Hello world. How @are you ? Hope that @you are @doing well. Can you @please suggest me?"; 

NSArray *arr = [str componentsSeparatedByString:@" "]; 

NSMutableArray *resultArr = [[NSMutableArray alloc]init]; 
NSMutableArray *resultArr2 = [[NSMutableArray alloc]init]; 

for (int i = 0; i < arr.count; i++) { 


    if ([[[arr objectAtIndex:i] substringToIndex:1] isEqualToString:@"@"]) { 

     [resultArr addObject:[arr objectAtIndex:i]]; 


    } 

} 

    // NSLog(@"result Arr : %@",resultArr); 

for (int j = 0; j < resultArr.count; j++) { 



    NSLog(@"%@ = %d",[resultArr objectAtIndex:j],j); 
    NSDictionary *temp = [NSDictionary dictionaryWithObject:[resultArr objectAtIndex:j] forKey:[NSString stringWithFormat:@"%d",j]]; 
    [resultArr2 addObject:temp]; 
} 


NSLog(@"array 2 : %@",resultArr2);