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

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

NSString *string = @" spaces in front and at the end "; 


NSString *trimmedString = [string stringByTrimmingCharactersInSet:


[NSCharacterSet whitespaceAndNewlineCharacterSet]];


NSLog(trimmedString)