中文转换为16进制
最近在学习IC卡的数据读写,遇到个问题,在C#中怎样才能将textbox里的中文转换为16进制写入到IC卡里呢? --------------------编程问答--------------------string input = "Hello World!";--------------------编程问答-------------------- 看不懂1楼的.... --------------------编程问答-------------------- 那就在看看这个吧
char[] values = input.ToCharArray();
foreach (char letter in values)
{
// Get the integral value of the character.
int value = Convert.ToInt32(letter);
// Convert the decimal value to a hexadecimal value in string form.
string hexOutput = String.Format("{0:X}", value);
Console.WriteLine("Hexadecimal value of {0} is {1}", letter, hexOutput);
}
/* Output:
Hexadecimal value of H is 48
Hexadecimal value of e is 65
Hexadecimal value of l is 6C
Hexadecimal value of l is 6C
Hexadecimal value of o is 6F
Hexadecimal value of is 20
Hexadecimal value of W is 57
Hexadecimal value of o is 6F
Hexadecimal value of r is 72
Hexadecimal value of l is 6C
Hexadecimal value of d is 64
Hexadecimal value of ! is 21
*/
http://www.codesky.net/article/doc/200806/2008060324034918.htm --------------------编程问答--------------------
--------------------编程问答-------------------- for (int i = 0; i < stringText.Length; i++)
string s = "这里是中文";
byte[] data = Encoding.Default.GetBytes(s);//这里就得到了对应的字节数组
StringBuilder builder = new StringBuilder();//定义stringbuilder用于组合16进制的字符串
foreach (byte b in data)
{
builder.Append(b.ToString("X02") + " ");//空格分割
}
Console.WriteLine(builder.ToString().TrimEnd());//去掉最末尾的多余空格并打印。你替换为你的发送即可。
{
str+= "\\u" + ((int)stringText[i]).ToString("x");
} --------------------编程问答-------------------- 代码的数量和等级成反比。。。
补充:.NET技术 , C#