The method commonly used to ensure data identical length

 

Can be used to write the log of the time, they look better

 

        ///  <Summary> 
        /// ensure that the same data length
         ///  </ Summary> 
        ///  <param name = "obj"> </ param> 
        ///  <param name = "len"> </ param> 
        ///  <param name = "afterFill"> after the filling / before filling </ param> 
        ///  <Returns> </ Returns> 
        public  String GetSameLenString ( Object obj, int len = 30 , BOOL afterFill = to true ) 
        { 
            String name = obj.toString ();
             // int len = COUNT - name.Length;// can not use this in English and Chinese characters occupy different lengths 
            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;
            }
        }

 

Guess you like

Origin www.cnblogs.com/guxingy/p/11362785.html