Objective-C中trim的实现


在java,javascript中,都有trim的系统实现(将字符串的首尾空格去掉),但在iOS开发中,却没有找到现成的trim方法的实现,只有自己实现该方法了,下面是实现trim方法的实现:

  1. NSString *string = @" spaces in front and at the end ";   
  2. NSString *trimmedString = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];   
  3. NSLog(@"%@",trimmedString) ;  

相关内容