oc 字符串 如何去掉前后空格、回车键

if ([title hasPrefix:@" "]) {

            title = [title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];//去掉前后空格

        }else if([title hasPrefix:@" "]){

            title = [title stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];//去掉前后回车键

        }else{

    title = [title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];//去掉前后空格+回车键

            title = [NSString stringWithFormat:@"%@",headLinesModel.title];

        }

原文地址:https://www.cnblogs.com/lrr0618/p/6651413.html