1、將字元轉換成byte陣列
string str = "羅長";
byte sb = str.getbytes();
2、將byte陣列轉換成字元
byte b=;
string str= new string (b);
一、字串轉位元組陣列
string str = 「金燦燦」;
byte bytes = str.getbytes();
如果轉換的時候不設定編碼格式,預設是以環境的字符集編碼。
1.utf-8 : byte bytes = str.getbytes(「utf-8」);//中文是佔三個位元組
2.gbk : byte bytes = str.getbytes(「gbk」);//中文是佔兩個位元組
二、位元組陣列轉字串
1.utf-8 : string s = new string(bytes ,「utf-8」);
2.gbk : string s = new string(bytes ,「gbk」);
字串 位元組陣列 字元陣列之間的轉換
package stringexample 1.字串與基本資料型別 包裝類之間的轉換 字串 基本資料型別 包裝類 呼叫相應的包裝類的pa xx string str 基本資料型別 包裝類 字串 字串過載的valueof 方法 2.字串與位元組陣列 字串 位元組陣列 字串的getbytes 位元組陣列...
C 字串和位元組陣列轉換
定義string變數為str,記憶體流變數為ms,位元陣列為bt 1.字串轉位元陣列 1 byte bt system.text.encoding.default.getbytes 字串 2 byte bt convert.frombase64string 字串 2.字串轉流 1 memorystr...
字串與位元組陣列的轉換
字串與位元組陣列的轉換 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...