c#_string與byte[]之間的轉換

先將stirng s 轉換成byte[]存放到source中,在將source中的byte拷貝source.Length個到destin中。

string s = "test string";
byte[] source = new byte[ 100 ];
bute[] destin = new byte[ 512 ];

source = System.Text.Encoding.Unicode.GetBytes( s );
System.Array.Copy( source, destin, source.Length );

bytes 轉換成 string:
s = System.Text.Encoding.Unicode.GetString( destin, 0, destin.Length )

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章