iOS 过滤空格

    //过滤空格

    NSString * urlStr = @"   A as    dd  dmm ";

    NSLog(@"urlStr = %@",urlStr);

    

    //过滤字符串前后的空格

    urlStr = [urlStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

    NSLog(@"urlStr = %@",urlStr);

    

    //过滤中间空格

    urlStr = [urlStr stringByReplacingOccurrencesOfString:@" " withString:@""];

    NSLog(@"urlStr = %@",urlStr);

你可能感兴趣的:(NSString,过滤空格)