Convert string to byte[] và ngược lại với VB .Net và C#
' 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);
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);
Bài viết cùng danh mục
- Convert UTF-8 and ASCII encoded bytes back to UTF-16 encoded string: chuyển đổi UTF-8, ASCII, UTF-16...
- Decimal Number to Binary String: Chuyển số thập phân sang dạng nhị phân
- Developing MDI Applications in C#: phát triển ứng dụng MDI trong lập trình C#
- Đọc file vào byte[] / lấy dữ liệu cho mảng byte từ file
- Dòng lệnh dịch thư viện .Net
- Export ASP.Net DataGrid DataSet To CSV File: xuất dữ liệu từ điều khiển DataGrid Dataset sang file CSV trong lập trình Asp.Net
- Export DataGridView to Excel
- Hàm thực hiện việc upload trong lập trình ASP .net
- Hàm xóa file trong C#
- Find a control in vb.net: tìm một điều khiển trong lập trình Asp .net (ngôn ngữ VB. Net)
- GDI - Vẽ bằng GDI+ với C#
- Hàm kiểm tra kích thước file tranh (image)
- Hàm tạo thumbnail (ảnh minh minh họa, thu nhỏ từ một ảnh có kích thước lớn)
- KeyPress Kiểm tra phím bấm là số
- Mở một File, ứng dụng,...từ VB .Net
- Chương trình minh họa Multi-threaded trong C#
- Phân trang trong DataList C#
- Phân trang trong DataList C#
- Đọc và viết file nhị phân trong C#
- Đọc và viết file văn bản (text)
Câu chuyện Đào giếng
![]() |