C#字符格式化占位符
using System; using System.Diagnostics; using System.Text; using System.Collections; using System.Collections.Generic; class Test { public delegate void deltest(string str); public static void Callbk(string str) { Console.WriteLine(str); } static void Main() { byte[] bs = { 97, 98, 99, 100 }; StringBuilder sb = new StringBuilder(); for(int i=0; i<bs.Length; ++i) { sb.Append(bs[i].ToString("x3"));//16进制,占3个字符宽度 sb.Append(bs[i].ToString().PadLeft(4, '_'));//占4字符宽度,不足用下划线填充 } Console.WriteLine(sb); //061062063064 } }