- //删除空格对象方法实现
- - (NSString *) spaceDelete
- {
- //记录开头几个空格
- int m = 0;
-
- //记录结尾处几个空格
- int n = 1;
-
- //查看开头
- for (int i = 0; i < self.length && [self characterAtIndex:i] !=32; i++)
- {
- if ([self characterAtIndex:i] == 32) {
- m++;
- }
- }
-
- //查看结尾
- for (NSUInteger i = self.length-1; i > 0 && [self characterAtIndex:i] !=32; i--)
- {
- if ([self characterAtIndex:i] == 32) {
- n++;
- }
- }
-
- //确定新字符串的范围
- NSRange r = {m , self.length-n};
-
- //[self substringWithRange:r]截取这个范围内的字符
-
- NSString *str = [self substringWithRange:r];
-
- return str;
- }
复制代码
作用是删除字符串前面与后面的空格,编译没问题,运行也没问题,但是就是不删除。 |
|