- Lua Quick Start Guide
- Gabor Szauer
- 121字
- 2021-08-05 10:30:37
String length
There are two ways to get the length of a string, either using the string.len() function, or by placing a # symbol in front of the string. Both methods work the same way, and they both return a number value. This number can be assigned to a variable or used in its place. You can call either method on a variable, or directly on a string. The following code demonstrates all of these concepts:
hello = "hello, world"
-- Assign length to variables
count_hash = #hello;
count_func = string.len(hello)
print ("The string:")
print (hello)
-- Print the variables assigned at the top
print ("Has a length of:")
print (count_hash)
print(count_func)
-- Use string literals, in place
print (#"hello, world")
print (string.len("hello, world"))
推薦閱讀
- Functional Python Programming
- Python程序設計教程(第2版)
- Vue.js快速入門與深入實戰
- Architecting the Industrial Internet
- 小學生C++創意編程(視頻教學版)
- Hands-On Full Stack Development with Go
- 軟件品質之完美管理:實戰經典
- PHP從入門到精通(第4版)(軟件開發視頻大講堂)
- 深入淺出React和Redux
- Node學習指南(第2版)
- BeagleBone Robotic Projects(Second Edition)
- 3ds Max印象 電視欄目包裝動畫與特效制作
- Mockito Essentials
- C++從入門到精通(第6版)
- WordPress Search Engine Optimization(Second Edition)