C# 中的阿拉伯语表示形式 B 支持 [英] Arabic presentation forms B support in c#

查看:26
本文介绍了C# 中的阿拉伯语表示形式 B 支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 C# 中的编码 API将文件从 utf-8 转换为阿拉伯语-1265 编码,但我遇到了一个奇怪的问题,即某些字符没有正确转换,例如لا" 在下面的语句ﻣﺣﻣد ﺻﻼ ح عادل"中,它显示为ﻣﺣﻣد ﺻ? ح عادل".我的一些朋友告诉我,这是因为这些字符来自阿拉伯语演示文稿 B.我使用 notepad++ 创建文件并将其保存为 utf-8.

I was trying to convert a file from utf-8 to Arabic-1265 encoding using the Encoding APIs in C#, but I faced a strange problem that some characters are not converted correctly such as "لا" in the following statement "ﻣﺣﻣد ﺻﻼ ح عادل" it appears as "ﻣﺣﻣد ﺻ? ح عادل". Some of my friends told me that this is because these characters are from the Arabic Presentation Forms B. I create the file using notepad++ and save it as utf-8.

这是我使用的代码

    StreamReader sr = new StreamReader(@"C:\utf-8.txt", Encoding.UTF8);
    string str = sr.ReadLine();
    StreamWriter sw = new StreamWriter(@"C:\windows-1256.txt", false, Encoding.GetEncoding("windows-1256"));
    sw.Write(str);
    sw.Flush();
    sw.Close();

但是,我不知道如何在 C# 中使用此演示文稿形式正确转换文件.

But, I don't know how to convert the file correctly using this presentation forms in C#.

推荐答案

是的,您的字符串包含许多无法在 1256 代码页中表示的连字.在写入之前,您必须分解字符串.像这样:

Yes, your string contains lots of ligatures that cannot be represented in the 1256 code page. You'll have to decompose the string before writing it. Like this:

  str = str.Normalize(NormalizationForm.FormKD);
  st.Write(str);

这篇关于C# 中的阿拉伯语表示形式 B 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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