ios 字符串去除两端的空白 字符串去除所有空白

// 字符串去除两端的空白

+ (NSString *)removeWhitespaceAndNewlineFromBothEnd:(NSString *)str

{

    NSCharacterSet *whitespace = [NSCharacterSet  whitespaceAndNewlineCharacterSet];

    return [str stringByTrimmingCharactersInSet:whitespace];

}


// 字符串去除所有空白

+ (NSString *)removeAllWhitespace:(NSString *)str

{

    NSString *tmpStr = [self removeWhitespaceAndNewlineFromBothEnd:str];

    NSString *finalString = [tmpStr stringByReplacingOccurrencesOfString:@" " withString:@""];

    return finalString;

}

你可能感兴趣的:(ios学习与开发笔记)