**:
/*** 將byte轉換為string 或者將string轉換為byte
* * @author administrator
* */
public class byteorstringhelper
/*** @param str 源字串轉換成位元組陣列的字串
* @return
*/public static byte stringtobyte(string str)
/***
* @param srcobj 源位元組陣列轉換成string的位元組陣列
* @return
*/public static string bytetostring(byte srcobj)
/*** utf-8 乙個漢字佔三個位元組
* @param str 源字串
* 轉換成位元組陣列的字串
* @return
*/public static byte stringtobyte(string str,string charencode) else
} catch (unsupportedencodingexception e)
return destobj;
}/**
* @param srcobj 源位元組陣列轉換成string的位元組陣列
* @return
*/public static string bytetostring(byte srcobj,string charencode) catch (unsupportedencodingexception e)
return destobj.replaceall("\0"," ");}}
C 字串與位元組陣列互轉
定義string變數為str,記憶體流變數為ms,位元陣列為bt 1.字串轉位元陣列 1 byte bt system.text.encoding.default.getbytes 字串 2 byte bt convert.frombase64string 字串 2.字串轉流 1 memorystr...
C 字串到位元組陣列,位元組陣列轉整型
int num 12345 string num1 convert.tostring 12345,16 byte bytes bitconverter.getbytes num 將int32轉換為位元組陣列 num bitconverter.toint32 bytes,0 將位元組陣列內容再轉成in...
C 字串與位元組陣列相互轉換
總結歸納 如果直接從system.string類中找到方法進行字串和位元組陣列之間的轉換,是不太可能的。為了使其之間進行轉換,需要借助另外乙個型別 system.text.encoding。這個型別提供了將c 字串轉換成位元組陣列的方法,也提供了將c 位元組陣列轉換成字串。system.text.e...