string.len
string.len Function | |
---|---|
Syntax string.len(
Colon notation: str:len() | |
Returns | number |
API | string |
Source | Lua (source) |
Return the number of bytes in str.
The number of bytes in a string is not necessarily equivalent to its amount of characters! Many Unicode characters take up more than one byte. For example,
string.len("รถ")
returns 2
. Hence, string.len only returns the amount of characters if str is encoded in an encoding that only uses one byte per character, such as ASCII.#str
.
|
|||
Read a line from the user, then print the length of the string they entered. | |||
Code | <nowiki>
print(string.len(read()))
</nowiki>
|
||
Output | Depends on what the user wrote. For instance, if they were to enter Hello World , the number printed would be 11 . |
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.