土耳其语ios [英] turkish characters ios

查看:171
本文介绍了土耳其语ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS编程的新手.我正在开发一个应用程序,该应用程序将从Web服务中获取一些句子,然后将其插入到本地数据库中. ü,ğ,ç,ö".我可以将这些字符很好地插入到数据库中,但是当我将它们输出到UILabel时,它看起来像:≈üƒü√º√∂".我试图转换为 NSUTF8StringEncoding ,但无济于事.

I am new to iOS programming. I am developing an app which gets some sentences from my web service which I insert into my local database However, some sentences contain turkish characters such as; "ü, ğ, ç, ö". I can insert these characters to in my database fine, but when I output them to a UILabel it looks like: "≈ü ƒü √º √∂". I have tried to convert to NSUTF8StringEncoding but to no avail.

我有一个NSMutableArray,名为问题,其中包含一些土耳其字符.如何将该数组转换为NSUTF8String格式?

I have an NSMutableArray, named questions, which contains some turkish characters. How can I convert this Array to NSUTF8String format?

对不起,我的英语不好:)谢谢.

Sorry for my bad english :) Thanks.

推荐答案

嗯,我认为问题不在于您需要转换数组-而是显示字符串的方式.

Ahh, I think the problem is not that you need to convert your array - it is how you display the strings.

检查此代码,其中包含一组土耳其足球运动员:

Check this code which has an array of Turkish footballers:

NSMutableArray *questions = [[NSMutableArray alloc] initWithObjects:@"Emre Belözoğlu", @"Gökhan Gönül", @"Mevlüt Erdinç", @"Nuri Şahin", nil];

const char *utf8string = [[NSString stringWithFormat:@"%@", [questions objectAtIndex:0]] UTF8String];
self.title = [NSString stringWithUTF8String:utf8string];

现在它应该以正确的格式将页面标题显示为"EmreBelözoğlu".

It should now display the title of the page as "Emre Belözoğlu" in correct formatting.

问题可能是数据从SQLite解析到您的NSMutableArray的方式.这是我为一级方程式应用程序实现的方法.

The problem could alternatively be with the way the data is parsed from the SQLite to your NSMutableArray. Here is how I have achieved it for a Formula 1 app.

viewDidLoad中,我呼叫[self loadNamesFromDatabase];,它看起来像:

In viewDidLoad I call [self loadNamesFromDatabase]; which looks like:

- (void)loadNamesFromDatabase
{
    NSString *file = [[NSBundle mainBundle] pathForResource:@"Formula1" ofType:@"sqlite"];
    sqlite3 *database = NULL;
    if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) {
        sqlite3_exec(database, "select driver_id, driver_name, driver_nation, driver_team from drivers", MyCallback, drivers, NULL);
    }
    sqlite3_close(database);
}

和您看到的MyCallback函数如下:

static int MyCallback(void *context, int count, char **values, char **columns)
{
    NSMutableArray *drivers = (NSMutableArray *)context;
    NSString *columnName;
    NSString *columnValue;
    NSMutableDictionary * record = [NSMutableDictionary dictionary];
    for (int i=0; i < count; i++) {
        columnName = [NSString stringWithUTF8String:columns[i]];
        if (values[i]){
            columnValue = [NSString stringWithUTF8String:values[i]];
        }
        else{
            columnValue = @"";
        }
        [record setObject:columnValue forKey:columnName]; 
    }
    [drivers addObject:record];

    return SQLITE_OK;
}

其中,driversNSMutableArray.关键是stringWithUTF8String,您无需使用顶部的代码,因为所有数据都应正确编码,从而可以正确显示.

where drivers is an NSMutableArray. The key thing here is stringWithUTF8String and you would not need to use the code at the top as all data should be encoded properly and thus will be presented correctly.

这篇关于土耳其语ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆