mat*_*mat -1 iphone cocoa-touch objective-c nsstring
我的代码工作得很好,直到知道,如果我在文本字段中输入一个双位数字(如12),nslog返回2个单位数字(如1和2).现在我需要将这2个单位数字放入2个字符串中.有人可以帮助我吗 提前致谢.
NSString *depositOverTotalRwy = [NSString stringWithFormat:@"%@", [deposit text]];
NSArray *components = [depositOverTotalRwy
componentsSeparatedByString:@"/"];
NSString *firstThird = [components objectAtIndex:0];
for(int i = 0; i < [firstThird length]; i++)
{
char extractedChar = [firstThird characterAtIndex:i];
NSLog(@"%c", extractedChar);
}
Run Code Online (Sandbox Code Playgroud)
你应该可以使用-stringWithFormat:.
NSString *s = [NSString stringWithFormat:@"%c", extractedChar];
Run Code Online (Sandbox Code Playgroud)
编辑:
您可以将它们存储在一个数组中.
NSMutableArray *digits = [NSMutableArray array];
for ( int i = 0; i < [s length]; i++ ) {
char extractedChar = [s characterAtIndex:i];
[digits addObject:[NSString stringWithFormat:@"%c", extractedChar]];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4204 次 |
| 最近记录: |