C#字符格式化占位符

时间:2023-12-11 16:29:02
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 = { , , , };
StringBuilder sb = new StringBuilder();
for(int i=; i<bs.Length; ++i)
{
sb.Append(bs[i].ToString("x3"));//16进制,占3个字符宽度
sb.Append(bs[i].ToString().PadLeft(, '_'));//占4字符宽度,不足用下划线填充
} Console.WriteLine(sb); //
} }