String length: Difference between revisions
Content deleted Content added
m oct... |
|||
Line 261:
{{works with|C sharp|C #|1.0+}}
===
<lang cpp>string s = "Hello, world!";
int
Strings in .NET are stored in Unicode.
<lang cpp>using System.Text;
▲===Character Length===
int byteLength = Encoding.Unicode.GetByteCount(s);</lang>
▲<lang cpp>string s = "Hello, world!";
To get the number of bytes that the string would require in a different encoding, e.g., UTF8:
<lang cpp>int utf8ByteLength = Encoding.UTF8.GetByteCount(s);</lang>
=={{header|Clean}}==
|