Object-c 字符串NSString中去掉空格

{app.params.name}} {app.params.name}} {app.params.name}} 1,使用NSString中的stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];//方法只是去掉左右两边的空格
2,使用NSString *strUrl = [urlString stringByReplacingOccurrencesOfString:@" " withString:@""];//使用替换的方法去掉空格

示例:

NSString *personIdString = [[NSString alloc] init];
for (id item in _compareDataDic) {
    personIdString = [personIdString stringByAppendingString:[NSString stringWithFormat:@"%@ ",[[_compareDataDic valueForKey:[NSString stringWithFormat:@"%@",item]] valueForKey:@"person_id"]]];
}
personIdString = [personIdString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
personIdString = [personIdString stringByReplacingOccurrencesOfString:@" " withString:@","];


_compareDataDic是一个NSMutableDictionary类型的变量


版权声明

davidzhang 创作并维护的 Gowhich 博客采用 创作共用保留署名-非商业-禁止演绎4.0国际许可证。

本文首发于 Gowhich 博客( https://www.gowhich.com ),版权所有,侵权必究。

本文永久链接: https://www.gowhich.com/blog/189

comments powered by Disqus