如何将字符串转换为字节数组? [英] How to Convert String to Byte Array?
本文介绍了如何将字符串转换为字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在阅读时出现错误:
无法将类型'String'隐式转换为'Byte []'
Cannot implicitly convert type 'String' to 'Byte[]'
我认为'byte []'是字节数组-如果不是,请纠正我.
I think 'byte[]' is byte array - if it isn't please correct me.
我在此网站上尝试了另一种解决方案,但我不理解.我正在制作一个c#"RTM工具",这是放在里面的:
I have tried another solution on this website but I did not understand. I'm making a c# 'RTM tool' and this is what put in :
byte[] bytes = (metroTextBox2.Text);
Array.Resize<byte>(ref bytes, bytes.Length + 1);
PS3.SetMemory(0x2708238, bytes);
推荐答案
您可以尝试以下操作:
string str= "some string";
var bytes = System.Text.Encoding.UTF8.GetBytes(str);
并进行解码:
var decodeString = System.Text.Encoding.UTF8.GetString(bytes);
这篇关于如何将字符串转换为字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文