- 第一种
- #import <stdio.h>
- int main()
- {
- @autoreleasepool {
-
-
- NSString *str = @"123-456-789-000";
-
- NSMutableString *newStr = [NSMutableString string];
-
- for (int i = 0; i<str.length; i++) {
- char s = [str characterAtIndex:i];
-
- if (s != '-') {
- [newStr appendFormat:@"%c",s];
- }
-
- }
- NSLog(@"%@", newStr);
-
- }
- }
复制代码
- 第二种
- #import <stdio.h>
- int main()
- {
- @autoreleasepool {
-
-
- NSString *str = @"123-456-789-000";
-
-
- NSArray *array = [str componentsSeparatedByString:@"-"];
-
- NSMutableString *newStr = [NSMutableString string];
-
-
- for (id obj in array)
- {
- [newStr appendString:obj];
- }
-
-
- NSLog(@"%@",newStr);
-
- }
-
- }
复制代码 |