---
title: "字符串编码相关"
author: "Perrin Yong"
author_profile: https://www.pystone.net/profile/
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/string-encoding-basics/
type: note
content_role: unspecified
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/01-系统基础与网络安全/计算机与操作系统/字符串编码相关.md"
content_hash: 52795b73e1475ae162e96c47fa649e08be7a608fddf6cdbb096abbc06d7f0df8
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# 字符串编码相关

> 创建时间：2020/9/24 23:55

## 编码相关知识

字符编码（Character encoding）：
<https://dailc.github.io/2017/05/03/char_charset_charEncoding.html>
<https://dailc.github.io/2017/05/17/severalCommonlyCharEncoding.html>
[https://baike.baidu.com/item/ANSI/10401940?fromtitle=ansi%E7%BC%96%E7%A0%81&fromid=9421969](https://baike.baidu.com/item/ANSI/10401940?fromtitle=ansi%E7%BC%96%E7%A0%81&fromid=9421969)

## Windows cmd的编码

命令行显示中文乱码，大多是由于字符编码不匹配导致。

CMD默认编码格式为 (ANSI/OEM - 简体中文 GBK )，代码页为936

chcp 命令可以设置活动代码页编号。
65001

> 代码页 描述
>  65001 UTF-8代码页
>  950繁体中文
>  936简体中文默认的GBK
>  437 MS-DOS美国英语

### CSharp相关API

使用C#调用命令行可以通过以下语句设置CMD的编码格式

```xml
public class AGenericClass&lt;T&gt; where T : IComparable&lt;T&gt; { }

```

字节Buffer和字符串之间互相转换

```xml
public class AGenericClass&lt;T&gt; where T : IComparable&lt;T&gt; { }

```

Convert，目前还不清楚应用情景

```xml
public class AGenericClass&lt;T&gt; where T : IComparable&lt;T&gt; { }

```
