Get the byte array from a string using default encoding in CSharp
Description
The following code shows how to get the byte array from a string using default encoding.
Example
/*w w w. jav a 2 s . c o m*/
using System;
using System.Collections.Generic;
using System.Text;
public class SysUtil
{
public static void Main(String[] argv){
Console.WriteLine(StringToBytes("java2s.com").Length);
}
public static byte[] StringToBytes(String strData)
{
return System.Text.Encoding.GetEncoding(0).GetBytes(strData);
}
}
The code above generates the following result.