将字符转换为字符串
我的代码工作得很好,直到知道,如果我在文本字段中输入一个两位数数字(如 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);
}
my code works great until know and, if I put a double digit number into the text field (like 12) nslog returns 2 single digit numbers (like 1 and 2). Now I need to put these 2 single digit numbers into 2 strings. can somebody help me. thanks in advance.
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够使用
-stringWithFormat:
。编辑:
您可以将它们存储在数组中。
You should be able to use
-stringWithFormat:
.EDIT:
You can store them in an array.
尝试使用
NSLog()
打印 firstThird 的值,看看它到底包含什么,您的代码似乎是正确的,请使用
characterAtIndex
函数来NSString
在已知位置提取字符使用如下
Try to print the value of firstThird using
NSLog()
, see what it exactly hold, you code seem correct,Use
characterAtIndex
function forNSString
to extract a character at known locationUse as below