C 字串和位元組陣列轉換

2022-09-03 13:09:12 字數 932 閱讀 8173

**:

定義string變數為str,記憶體流變數為ms,位元陣列為bt

1.字串轉位元陣列

(1)byte bt=system.text.encoding.default.getbytes("字串");

(2)byte bt=convert.frombase64string("字串");

2.字串轉流

(1)memorystream ms=new memorystream(system.text.encoding.default.getbytes("字串"));

(2)memorystream ms=new memorystream(convert.frombase64string("字串"));

3.流轉位元陣列

(1)byte bt=ms.toarray();

(2)memorystream ms=new memorystream();ms.write(bt,0,ms.length);

4.流轉字串

(1)string str=convert.tobase64string(ms.toarray());

(2)string str=system.text.encoding.default.getstring(ms.toarray());

5.位元陣列轉字串

(1)string str=system.text.encoding.default.getstring(bt);

(2)string str=convert.tobase64string(bt);

6.位元陣列轉流

(1)memorystream ms=new memorystream(bt);

(2)memorystream ms=new memorystream();ms.read(bt,0,bt.lenght);

C 字串到位元組陣列,位元組陣列轉整型

int num 12345 string num1 convert.tostring 12345,16 byte bytes bitconverter.getbytes num 將int32轉換為位元組陣列 num bitconverter.toint32 bytes,0 將位元組陣列內容再轉成in...

C 位元組陣列轉換成字串

如下字串與位元組陣列互換的例子 byte msg encoding.unicode.getbytes textbox1.text this.label1.text encoding.unicode.getstring msg system.text.encoding 類似乎沒有可用的建構函式,但我們...

字串與位元組陣列的轉換

字串與位元組陣列的轉換 string str helloworld byte data str.getbytes for int x 0 x data.length x data x 32 system.out.print datd x system.out.println new string d...