[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]);
}
{
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]);
}
决不做一个程序代码的写手.