如何将Unicode字符串转换为字符?

如何将Unicode字符串转换为字符?

问题描述:

我有一个文本文件,其中多组 Unicode 被写入

i have a text file in which sets of Unicodes are written as

"'\u0641'","'\u064A','\u0649','\u0642','\u0625','\u0644','\u0627','\u0647','\u0631','\u062A','\u0643','\u0645','\u0639','\u0648','\u0623','\u0646','\u0636','\u0635','\u0633','\u0641','\u062D','\u0628','\u0650','\u064E','\u062C','\u0626""'\u0622'","'\u062E','\u0644','\u064A','\u0645".

"'\u0641'","'\u064A','\u0649','\u0642','\u0625','\u0644','\u0627','\u0647','\u0631','\u062A','\u0643','\u0645','\u0639','\u0648','\u0623','\u0646','\u0636','\u0635','\u0633','\u0641','\u062D','\u0628','\u0650','\u064E','\u062C','\u0626" "'\u0622'","'\u062E','\u0644','\u064A','\u0645".

我打开文件并使用 readline 方法开始读取文件.我将上面的行显示为一行,现在我想将所有 Unicode 转换为字符,以便我可以获得一个可读的字符串.我尝试了一些逻辑,但这不起作用我坚持将字符串'\u00641'"转换为字符.

I opened the file and started reading of file by using readline method. I got the above line shown as a line now i want to convert all Unicode to char so that i could get a readable string. i tried some logic but that doesn't worked i stuck with converting string "'\u00641'" to char.

您可以提取包含单个数字的字符串(例如使用 Regex),将 Int16.Parse 应用于每个字符串,然后将其转换为字符.

You can extract strings containing individual numbers (using Regex for example), apply Int16.Parse to each and then convert it to a char.

string num = "0641"; // replace it with extracting logic of your preference
char c = (char)Int16.Parse(num, System.Globalization.NumberStyles.HexNumber);