关于AppendFormat("{0:X2}")
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0:X2}", 10);
Response.Write(sb);
输出A
X2表示十六进制格式(大写),域宽2位,不足的左边填0。
- int[] recvLen = { 10, 11, 12, 13, 14, 15, 16, 17, 18 };
- StringBuilder uid = new StringBuilder();
- for (int i = 0; i <= recvLen.Length – 1; i++)
- uid.AppendFormat("{0:X2}\r\n", recvLen[i]);
- Console.WriteLine(uid.ToString());
输出:
0A
0B
0C
0D
0E
0F
10
11
12
from:http://blog.csdn.net/joyhen/article/details/41576841