我将字符串 (UTF-8) 转换为字符数组(在 C# 中)。并在控制台上显示字符数组,但无法在控制台中显示 UTF-8 字符。我该如何解决这个问题?我使用 IDE Visual Studio 2015 for C#using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace array{ class Program { #region Convert String to char array static void stringtochar() { string str0; Console.OutputEncoding = Encoding.UTF8; Console.Write("Nhập Chuỗi Ký Tự :"); str0 = Console.ReadLine(); Char[] str_arr = new Char[100]; // Create array Array.Copy(str0.ToCharArray(), str_arr,str0.Length); for (int i = 0; i < str0.Length; i++) { Console.Write("[{0}] => \"{1}\"", i, str_arr[i]); } Console.ReadLine(); } #endregion static void Main(string[] args) { stringtochar(); } }}输入字符串:hang out [0] => "d"[1] => "i"[2] => " "[3] => "c"[4] => "h"[5] => “o”[6] => “我”我希望输出为 [0] => "đ"
1 回答
qq_笑_17
TA贡献1818条经验 获得超7个赞
你的字符串是 unicode。所以将编码更改为 unicode 并添加输入编码
Console.OutputEncoding = Encoding.Unicode;
Console.InputEncoding = Encoding.Unicode;
- 1 回答
- 0 关注
- 153 浏览
添加回答
举报
0/150
提交
取消