标签:code else byte 相同 sum sys obj default color
可用于写日志的时候,对其好看些
/// <summary> /// 保证数据长度相同 /// </summary> /// <param name="obj"></param> /// <param name="len"></param> /// <param name="afterFill">后填充/前填充</param> /// <returns></returns> public string GetSameLenString(object obj, int len = 30, bool afterFill = true) { string name = obj.ToString(); //int count = len - name.Length;//不能用这个 汉字和英文占用的长度不同 int count = len - System.Text.Encoding.Default.GetBytes(name).Length; if (afterFill) { for (int i = 0; i < count; i++) { name += " "; } return name; } else { string value = ""; for (int i = 0; i < count; i++) { value += " "; } value += name; return value; } }
标签:code else byte 相同 sum sys obj default color
原文地址:https://www.cnblogs.com/guxingy/p/11362785.html