我想参照目标C中的其他字符串修改一个NSString,有人能帮我吗?
Example1:
a. "ab cd eg"
b. "ctghml"
I want to change string b like "ct gh ml" , in short want to insert space spaces exactly like string a.
Note: Number of letters will be same like (abcdeg).count = 6 and (ctghml).count = 6Example2:
a. (abcd) edt-tf
b. (lght)ert-tg
I want to change string b like "(lght) ert-tg" , in short want to insert space spaces exactly like string a.
Note: Number of letters will be same without spaces like ((abcd)edt-tf).count = 12 and ((lght)ert-tg).count = 12谢谢!
发布于 2017-03-28 05:56:11
NSString *str1 = @"ab cd eg";
NSMutableString *str2 = [@"ctghml" mutableCopy];
for(int i = 0; i < str1.length; i++) {
unichar c = [str1 characterAtIndex:i];
if (c == ' ') {
[str2 insertString:@" " atIndex:i];
}
}
NSLog(@"%@", str2);https://stackoverflow.com/questions/43061356
复制相似问题