开发者

C# Load List Unicode Charcters

开发者 https://www.devze.com 2023-02-24 05:15 出处:网络
I am wanting to load a list, some of the characters in the list aren\'t normal characters so C# replaces them with \"?\", how can I get around this?

I am wanting to load a list, some of the characters in the list aren't normal characters so C# replaces them with "?", how can I get around this?

Thanks.

System.IO.StreamReader sr = new System.IO.StreamReader(of.FileName);

            string xd = sr.ReadToEnd();

            string[] qt = xd.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmp开发者_如何学运维tyEntries);

            foreach (string text in qt)
            {
                string[] sn = text.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

                listSNL.Items.Add(sn[0]);
                m_Passwords.Add(sn[0], Encoding.ASCII.GetBytes(sn[1]));
            }

            sr.Close();

None of the answers so far below worked, it errors when I start at sr.ReadToEnd because it's automatically converted to a string and by unicode I mean characters like: £&½


Have you tried replacing this line:

m_Passwords.Add(sn[0], Encoding.ASCII.GetBytes(sn[1]));

with this one:

m_Passwords.Add(sn[0], Encoding.Unicode.GetBytes(sn[1]));


You could also use Encoding.UTF8 rather than Encoding.Unicode. If most of the characters are <= 127, it will require fewer bytes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号