从 UTF-8 文本文件中读取阿拉伯文本?
各位, 当尝试从给定文件中读取“阿拉伯文本”时,我遇到了一个奇怪(愚蠢)的问题。让我们假设我有一个名为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为没有办法自动强制从右到左布局。但是,您可以创建一种方法来反转文本。这将读取每个字符并将其放入可变字符串中。快速搜索后发现:
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: