iOS 去除空白格
发布网友
发布时间:2023-01-15 17:32
我来回答
共1个回答
热心网友
时间:2023-10-15 03:28
- (NSString *)noWhiteSpaceString {
NSString *newString = self;
// newString = [newString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; //去除掉首尾的空白字符和换行字符
newString = [newString stringByReplacingOccurrencesOfString:@"\r" withString:@""];
newString = [newString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
newString = [newString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; //去除掉首尾的空白字符和换行字符使用
newString = [newString stringByReplacingOccurrencesOfString:@" " withString:@""];
// 可以去掉空格,注意此时生成的strUrl是autorelease属性的,所以不必对strUrl进行release操作!
// newString = [newString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
return newString;
}