ios - 如何处理搜寻字词中的空格

标签 ios string search space

我正在使用以下代码段实现搜索。

-(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

我的搜索无法正常工作,因为它无法处理“史诗”和“标题”之间的空格。如何修改搜索词,以便可以处理间距?

最佳答案

在结果字符串上调用stringByAddingPercentEscapesUsingEncoding以根据URL规则对空格字符进行编码。

关于ios - 如何处理搜寻字词中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10458410/

相关文章:

ios - 在 opengl-es iOS 中建立索引

c++ - 在代码中定义字符串与控制台输入之间的区别

字符处理和字符串操作

algorithm - 寻找 2 变量函数的解决方案

go - ldap搜索过滤器以检查特定域下是否存在任何用户

ios - 使用 "more"按钮像 Instagram 一样在 UITableView 中扩展 UILabel

objective-c - NSData转换为NSString吗?

iOS 应用程序开发 Windows 上的 PhoneGap 或 Xamarin

javascript - 我们如何使用以正则表达式开头的字符串 (/^myString/g)

javascript - 尝试使用数组和对象在 JavaScript 中创建字典