' VB.NET to convert a string to a byte array
Public Shared Function StrToByteArray(str As String) As Byte()
Dim encoding As New System.Text.ASCIIEncoding()
Return encoding.GetBytes(str)
End Function 'StrToByteArray
// C# to convert a string to a byte array.
public static byte[] StrToByteArray(string str)
{
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
return encoding.GetBytes(str);
}
' VB.NET to convert a byte array to a string:
Dim dBytes As Byte() = ...
Dim str As String
Dim enc As New System.Text.ASCIIEncoding()
str = enc.GetString(dBytes)
// C# to convert a byte array to a string.
byte [] dBytes = ...
string str;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
str = enc.GetString(dBytes);
728x90
반응형
'C#' 카테고리의 다른 글
| DataSet 압축 (0) | 2009.04.03 |
|---|---|
| SQL Injection (0) | 2009.04.03 |
| DotNetZip revs to v1.6 – now with Unicode support (0) | 2009.02.20 |
| .Net Zip Library (0) | 2009.02.20 |
| 저장 프로시저 schema 검색 (0) | 2009.02.20 |