从 UTF-8 文本文件中读取阿拉伯文本?

发布于 2024-11-01 01:26:22 字数 1084 浏览 1 评论 0原文

各位, 当尝试从给定文件中读取“阿拉伯文本”时,我遇到了一个奇怪(愚蠢)的问题。让我们假设我有一个名为 TEXT.txt 的文本文件,它是 UTF-8 编码的,看起来像这样(阿拉伯文本是从右到左):

                                                                 :xxx xxxx xx xxx

                                                          .xxx, xxxxxxx xxxxx xxx

当我尝试使用

UITextView *about;
about.textAlignment = UITextAlignmentRight;
NSString *textFilePath = [[NSBundle mainBundle] pathForResource:@"TEXT" ofType:@"txt"];
NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath encoding:NSUTF8StringEncoding error:nil];
about.text = fileContents;
NSLog(@"The text is: \n %@",about.text);

Which is I believe is 来读取 Xcode 中的 TEXT.txt 时正道!!!然后它在 iPhone 模拟器和设备上显示如下:

                                                                 xxx xxxx xx xxx:

                                                          xxx, xxxxxxx xxxxx xxx.

Which is not the right text to be shown !!!!!!!!!!!!!!! “:”冒号和“.”到底是什么问题?时期走向错误的一边。我对这个问题很头疼,因为我已经尝试解决很长时间了。所以请帮忙!!!

此致;

Dear All,
I have a strange (stupid) problem when trying to read "Arabic text" from a given file. Let us assume that I have a text file called TEXT.txt which is encoded UTF-8 and looks like this (Arabic text is from RightToLeft):

                                                                 :xxx xxxx xx xxx

                                                          .xxx, xxxxxxx xxxxx xxx

When I am trying to read TEXT.txt in Xcode by using

UITextView *about;
about.textAlignment = UITextAlignmentRight;
NSString *textFilePath = [[NSBundle mainBundle] pathForResource:@"TEXT" ofType:@"txt"];
NSString *fileContents = [NSString stringWithContentsOfFile:textFilePath encoding:NSUTF8StringEncoding error:nil];
about.text = fileContents;
NSLog(@"The text is: \n %@",about.text);

Which is I believe is the right way!!! Then it shows on iPhone Simulator and on the device as this:

                                                                 xxx xxxx xx xxx:

                                                          xxx, xxxxxxx xxxxx xxx.

Which is not the right text to be shown !!!!!!!!!!!!!! What the heck is the problem of the ":" colon and the "." period going on the wrong side. I had a headache of this problem as I have been trying to solve for a long time already. So please Help!!!

Best Regards;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┼── 2024-11-08 01:26:22

我认为没有办法自动强制从右到左布局。但是,您可以创建一种方法来反转文本。这将读取每个字符并将其放入可变字符串中。快速搜索后发现:

-(NSString *) reverseString
{
  NSMutableString *reversedStr;
  int len = [self length];

  // Auto released string
  reversedStr = [NSMutableString stringWithCapacity:len];     

  // Probably woefully inefficient...
  while (len > 0)
    [reversedStr appendString:
         [NSString stringWithFormat:@"%C", [self characterAtIndex:--len]]];   

  return reversedStr;
}

I don't think there is a way to automatically force right to left layout. However, you can make a method that will reverse your text. This will read each character and putting it into a mutable string. A quick search came up with this:

-(NSString *) reverseString
{
  NSMutableString *reversedStr;
  int len = [self length];

  // Auto released string
  reversedStr = [NSMutableString stringWithCapacity:len];     

  // Probably woefully inefficient...
  while (len > 0)
    [reversedStr appendString:
         [NSString stringWithFormat:@"%C", [self characterAtIndex:--len]]];   

  return reversedStr;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文