将两个字符串组合成不同的语言RTL&轻铁 [英] Combine Two String in different Language RTL & LTR

查看:69
本文介绍了将两个字符串组合成不同的语言RTL&轻铁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种文字,一种是希伯来语,一种是英语.

在第一个文本中,我有希伯来语中的日期.

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSLocale *hebrew = [[NSLocale alloc] initWithLocaleIdentifier:@"he_IL"]; // Hebrew

    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'hh:mm:ss.SSSZ"];

    NSDate *date = [dateFormatter dateFromString:model.startDate];

    NSLog(@"%@", date);

    [dateFormatter setDateFormat:@"EEEE,dd.MM.yyyy"];
    dateFormatter.locale = hebrew;
    NSString *strDate = [dateFormatter stringFromDate:date];

,开始日期是:NString对象strDate中的יוםשישי,19.08.2016

另一方面,我在NSString对象timeForRequest中有文本 07:00-16:00

我需要的格式为 2016年1月15日| 16:00-07:00

,当我尝试对以下代码进行同样操作

[NSString stringWithFormat:@"%@ | %@",strDate,timeForRequest]

它向我显示了这样的内容:יוםשישי,19.08.2016 | 07:00-16:00

观察时间不正确,请帮助我摆脱这种联系.

先谢谢了.

解决方案

我很确定这里的问题是strDate中的希伯来语日期带有unicode字符,使其从右到左显示.在timeForResponse中与普通"从左到右字符串结合使用时,会引起混乱.日期格式化程序是从希伯来语区域设置中提取的.

尝试一下:

  1. 将日期格式字符串更改为

[dateFormatter setDateFormat:@"dd.MM.yyyy,EEEE"];

  1. 将您的字符串格式更改为

NSString *result = [NSString stringWithFormat:@"\u200E%@ | %@", timeForRequest, strDate];

0x200E unicode字符是不可见的,但会将渲染放回从左到右的模式.

在上面之后,这是我得到的输出:

07: 00-16: 00 | 17.08.2016,יום רביעי

I have two text, one in Hebrew language and one in English.

In first text I have date that is in Hebrew.

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSLocale *hebrew = [[NSLocale alloc] initWithLocaleIdentifier:@"he_IL"]; // Hebrew

    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'hh:mm:ss.SSSZ"];

    NSDate *date = [dateFormatter dateFromString:model.startDate];

    NSLog(@"%@", date);

    [dateFormatter setDateFormat:@"EEEE,dd.MM.yyyy"];
    dateFormatter.locale = hebrew;
    NSString *strDate = [dateFormatter stringFromDate:date];

and start Date is : יום שישי,19.08.2016 in NString object strDate

On other hand I have text 07: 00-16: 00 in NSString object timeForRequest

My needed format is יום שני, 15.01.2016 | 16:00 - 07:00

and when I try to do same with following code

[NSString stringWithFormat:@"%@ | %@",strDate,timeForRequest]

it shows me like this :יום שישי,19.08.2016 | 07: 00-16: 00

Observe the time is not correct, please help me to come out from this wired situation.

Thanks in advance.

解决方案

I'm pretty sure that the problem here is that the hebrew date in strDate is carrying unicode characters that make it display right-to-left. That's causing chaos when combined with the 'ordinary' left-to-right string in timeForResponse. The date formatter is picking that up from the hebrew locale.

Try this:

  1. Change your date format string to

[dateFormatter setDateFormat:@"dd.MM.yyyy,EEEE"];

  1. Change your string with format to

NSString *result = [NSString stringWithFormat:@"\u200E%@ | %@", timeForRequest, strDate];

The 0x200E unicode character is invisible but puts the rendering back into left-to-right mode.

After the above, this is the output that I'm getting:

07: 00-16: 00 | 17.08.2016,יום רביעי

这篇关于将两个字符串组合成不同的语言RTL&轻铁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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