组合不同语言 RTL 和 LTR 中的两个字符串

Combine Two String in different Language RTL & LTR

我有两篇文章,一篇是希伯来文,一篇是英文。

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

    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];

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

另一方面,我在 NSString 对象 timeForRequest

中有文本 07: 00-16: 00

我需要的格式是 əום שני, 15.01.2016 | 16:00 - 07:00

当我尝试对以下代码执行相同操作时

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

它显示我是这样的:יום שישי,19.08.2016 | 07:00-16:00

观察时间不对,请帮我从有线状态中解脱出来。

提前致谢。

我很确定这里的问题是 strDate 中的希伯来语日期带有 unicode 字符,使其从右到左显示。当与 timeForResponse 中的 'ordinary' 从左到右的字符串结合使用时,这会导致混乱。日期格式化程序正在从希伯来语语言环境中选取它。

试试这个:

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

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

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

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

0x200E unicode 字符是不可见的,但会将渲染恢复为从左到右的模式。

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

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

我只需要从 Debug 更改为 Release 并安装 Release .exe,现在这两个服务都是 运行 并且工作没有任何问题