iOS 字串過濾空格

weixin_34337265發表於2016-03-23
//過濾空格
NSString * urlStr = @"  A as    dd  dmm ";
NSLog(@"urlStr = %@",urlStr);
//過濾字串前後的空格
urlStr = [urlStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSLog(@"urlStr = %@",urlStr);
//過濾中間空格
urlStr = [urlStr stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"urlStr = %@",urlStr);

相關文章