如何知道字符串的字节的大小?字符串、字节、大小

2023-09-02 11:56:45 作者:欲哭无泪最心酸

我想知道如果我能知道过了多久在在C#中的字符串字节,谁知道?

I'm wondering if I can know how long in bytes for a string in C#, anyone know?

推荐答案

您可以像使用ASCII编码使用,让每一个字节一个字符 System.Text.Encoding 类。

You can use encoding like ASCII to get a character per byte by using the System.Text.Encoding class.

或尝试这种

  System.Text.ASCIIEncoding.Unicode.GetByteCount(string);
  System.Text.ASCIIEncoding.ASCII.GetByteCount(string);