2012-05-05 1 views
1

다음 코드 스 니펫을 사용하여 검색을 구현하고 있습니다. '서사시'와 '헤드 라인'사이의 공간을 처리 할 수 ​​없습니다로검색어에서 공백을 처리하는 방법

-(void)getData:(NSString *)searchString 
{ 
    //Search string is the string the user keys in as keywords for the search. In this case I am testing with the keywords "epic headline" 
    searchString = [searchString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
    NSString *resourcePath = [NSString stringWithFormat:@"/sm/search?limit=100&term=%@&types[]=users&types[]=questions&types[]=topics",searchString]; 

    [self sendRequests:resourcePath]; 
} 


//URL sent to server as a result 
send Request /sm/search?limit=100&term=epic headline&types[]=users&types[]=questions&types[]=topics 

내 검색이 작동하지 않습니다. 간격을 처리 할 수 ​​있도록 검색어를 수정하려면 어떻게해야합니까?

답변

3

URL 규칙에 따라 필요에 따라 공백 문자를 인코딩하려면 결과 문자열에서 stringByAddingPercentEscapesUsingEncoding을 호출하십시오.