- #import "NSString+new.h"
- @implementation NSString (new)
- //字符串反转
- - (NSString *)reverse
- {
- NSMutableArray *array = [NSMutableArray array];
- for (NSUInteger i = self.length ; i > 0; i--) {
- [array addObject:[NSString stringWithFormat:@"%c",[self characterAtIndex:i-1]]];
- }
- return [array componentsJoinedByString:@""];
- }
- //计算英文字母个数
- - (int)countAlpha
- {
- int count = 0;
- for (NSUInteger i = 0; i < self.length; i++) {
- if(isalpha([self characterAtIndex:i]))
- count++;
- }
- return count;
- }
- //去除字符串两端空格
- - (NSString *)removeSpace
- {
- NSMutableString *temp = [NSMutableString stringWithString:self];
- while (isblank([temp characterAtIndex:0])) {
- [temp deleteCharactersInRange:NSMakeRange(0, 1)];
- }
- while (isblank([temp characterAtIndex:temp.length-1])) {
- [temp deleteCharactersInRange:NSMakeRange(temp.length-1, 1)];
- }
-
- return [NSString stringWithString:temp];
- }
- @end
复制代码 |