111,115
社区成员
发帖
与我相关
我的任务
分享 // 把一个“unicode字符串”格式化为全角字符占2个位置的“普通字符串”
// width<0 表示左对齐,右边填空格
// width>0 表示右对齐,左边填空格
public static string StrFormat(string s, int width)
{
Encoding code = Encoding.Default;
byte [] bs = code.GetBytes(s);
bool leftAlign = (width < 0 ? true : false);
if (width < 0) width = - width;
if (bs.Length >= width) return s;
if (leftAlign) return s.PadRight(width-bs.Length+s.Length);
return s.PadLeft(width-bs.Length+s.Length);
}Text = Encoding.Default.GetString(
Encoding.Default.GetBytes("a中d12文cd"), 0, 6); //a中d12
if(str.IsDigitOrLetter)
{
//...
}
else
{
//...
}