下面的代码在obj-C中从sqlite结果集构建一个字符串数组--数据是数字的--但是我想我需要这个数组是一个数字数组,而不是一个字符串数组。
我需要一些“数组addObject”行的帮助来使数组数字化吗?
//scan thru result set and add to array
while (sqlite3_step(statement) == SQLITE_ROW)
{
[array addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]];
}发布于 2014-01-06 21:08:46
while (sqlite3_step(statement) == SQLITE_ROW)
{
NSString *stringValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
[array addObject:@(stringValue.integerValue)];
}integerValue方法在NSString上将作为NSInteger返回字符串的数值。NSInteger是一个基本类型,不能插入到数组中。调用integerValue时的integerValue是用于将原语数字类型框入NSNumber对象中的文字语句,可以插入到数组中。
https://stackoverflow.com/questions/20958741
复制相似问题