我正在使用数据库来获取数据。数据库中有近750个问题。一些问题包含特殊字符,如“,......,”等,但在获取数据并在文本视图中打印时,它会转换为“?”。有没有办法删除这些一种符号并以原始格式打印。
我使用以下代码在textview中获取和显示。
qsql=[NSString stringWithFormat:@"Select * from mydata where col_1 = '365'"];
if(sqlite3_prepare_v2(database, [qsql UTF8String], -1, &statement, NULL) == SQLITE_OK) {
while (sqlite3_step(statement) == (SQLITE_ROW))
{
char *field0 = (char *)sqlite3_column_text(statement, 1);
char *field1 = (char *)sqlite3_column_text(statement, 2);
NSString *t1 = nil;
if(field0!=NULL){
t1 = [[NSString alloc] initWithUTF8String:field0];
//NSString *t1 = [[NSString alloc] initWithCString:field0 encoding:NSUTF8StringEncoding];
NSLog(@"%@jujuj" ,t1);
}
NSString *t2 = nil;
if(field1!=NULL){
t2 = [[NSString alloc] initWithUTF8String:field1];
NSLog(@"%@jhjhh" ,t2);
}
NSString *string=t1;
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@",."];
string = [[string componentsSeparatedByCharactersInSet:doNotWant] componentsJoinedByString:@""];
NSLog(@"%@jhgkjghkjg",string);
//NSLog(@"%@ %@",Q_NO, Q_NO1);
tv.text=t1;
tv1.text=t2;
[t1 release];
[t2 release];
}
}
答案 0 :(得分:0)
使用NSCharacterSet从字符串中删除该特殊字符
NSString *string = @"ram,...";
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@",."];
string = [[string componentsSeparatedByCharactersInSet:doNotWant] componentsJoinedByString:@""];
NSLog(@"%@",string);
答案 1 :(得分:0)
像这样使用
const char *sqlStatement = Select * from mydata where col_1 = '365'";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
while (sqlite3_step(compiledStatement) == SQLITE_ROW)
{
nsstring *t1 = [NSString stringWithFormat:@"%s",(char*)sqlite3_column_text(compiledStatement, 1)];