objective-C 中类似于C#中trim的方法(去掉字符串前后空格)

来源:互联网 发布:报纸版面编辑软件 编辑:程序博客网 时间:2024/04/30 20:19

在objective-c中去掉字符串前后空格的方法(类似于C#中的trim方法)如下: 

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