String length: Difference between revisions
no edit summary
No edit summary |
|||
Line 104:
PRINT LEN(a$)</lang>
{{works with|PureBasic}}▼
<lang PureBasic> a = Len("Hello World") ;a will be 11</lang>▼
===Byte Length===▼
Returns the number of bytes required to store the string in memory in the given format in bytes. 'Format' can be #PB_Ascii, #PB_UTF8 or #PB_Unicode. PureBasic code can be compiled using either Unicode (2-byte) or Ascii (1-byte) encodings for strings. If 'Format' is not specified, the mode of the executable (unicode or ascii) is used. ▼
Note: The number of bytes returned does not include the terminating Null-Character of the string. The size of the Null-Character is 1 byte for Ascii and UTF8 mode and 2 bytes for Unicode mode. ▼
<lang PureBasic>a = StringByteLength("ä", #PB_UTF8) ;a will be 2▼
b = StringByteLength("ä", #PB_Ascii) ;b will be 1▼
c = StringByteLength("ä", #PB_Unicode) ;c will be 2▼
</lang>▼
=={{header|C}}==
Line 761 ⟶ 746:
For UTF-8:
<lang powershell>[System.Text.Encoding]::UTF8.GetByteCount($s)</lang>
===Character Length===
▲<lang PureBasic> a = Len("Hello World") ;a will be 11</lang>
▲===Byte Length===
▲Returns the number of bytes required to store the string in memory in the given format in bytes. 'Format' can be #PB_Ascii, #PB_UTF8 or #PB_Unicode. PureBasic code can be compiled using either Unicode (2-byte) or Ascii (1-byte) encodings for strings. If 'Format' is not specified, the mode of the executable (unicode or ascii) is used.
▲Note: The number of bytes returned does not include the terminating Null-Character of the string. The size of the Null-Character is 1 byte for Ascii and UTF8 mode and 2 bytes for Unicode mode.
▲<lang PureBasic>a = StringByteLength("ä", #PB_UTF8) ;a will be 2
▲b = StringByteLength("ä", #PB_Ascii) ;b will be 1
▲c = StringByteLength("ä", #PB_Unicode) ;c will be 2
▲</lang>
=={{header|Python}}==
|