[C#]文本内容的大小

代码
        private void GetTextSize()
        {
            
byte[] bys = Encoding.Default.GetBytes(richTextBox1.Text);
            LB_TextSize.Text 
= String.Format("{0},文字长度:{1}", richTextBox1.Text.Length,GetSize(bys.Length));

        }
        
private string GetSize(decimal size)
        {
            
string[] unit = new string[] {"B","KB","MB","GB","TB" };
            
int i=0;
            
for (; i < unit.Length-1 && size > 1024; i++)
            {
                size 
= size / 1024;
            }
            
return String.Format("{0} {1}", Math.Round(size, 4), unit[i]);
        }

 

posted @ 2010-01-18 11:35  竹子小毅  阅读(325)  评论(0编辑  收藏  举报