iOS - 去除字符串首尾空格、换行

  1. 去除首尾空格
NSString *title = [title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

  1. 去除首尾换行
NSString *title = [title stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
  1. 去除首尾空格和换行
NSString *title = [title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

摘自:https://blog.csdn.net/zhoupengju/article/details/52168926

你可能感兴趣的:(iOS - 去除字符串首尾空格、换行)