如何将文本文件的编码从UTF-8更改为各种其他编码,如十六进制和&十进制实体 [英] How to change the encoding of the text file from UTF-8 to various other encodings like hexadecimal & decimal entities

查看:298
本文介绍了如何将文本文件的编码从UTF-8更改为各种其他编码,如十六进制和&十进制实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在通过StreamReader阅读HTML文件。如何将HTML文件的编码从UTF-8更改为各种其他编码,如十六进制和十进制实体。



所有建议都表示赞赏。



期待听到您的想法。



热烈的问候,

Himanshu

Hi Everyone,

I am reading the a HTML file through "StreamReader". How can I change the encoding of the HTML file from UTF-8 to various other encoding like hexadecimal & decimal entities.

All the suggestions are appreciated.

Look forward to hear your thoughts.

Warm regards,
Himanshu

推荐答案

首先,UTF-8是一种编码,但十六进制和十进制不是:它们是数字格式,可能包含也可能不包含在您的文件中。



如果您的意思是您的文件包含文本格式的数字组:

Firstly, UTF-8 is an encoding, but "hexadecimal" and "decimal" aren't: they are numeric formats, which may or may not be contained in your file.

If you mean that your file contains groups of numbers in a text format:
1234,1A7F
5678,00FF
...

你想将它们转换成数学值,你可以用数学方法操作,然后你必须将每个数字分开并解析它。 br />
对于十六进制值:

And you want to convert them into numeric values that you can manipulate mathematically, then you have to separate each number, and parse it.
For hexadecimal values:

string inp = "1A7F";
int x = Convert.ToInt32(inp, 16);



对于十进制值:


For decimal values:

string inp = "1234";
int x = int.Parse(inp);






Or

string inp = "1234";
int x;
if (int.TryParse(inp, out x))
    {
    ...
    }


这篇关于如何将文本文件的编码从UTF-8更改为各种其他编码,如十六进制和&十进制实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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