- 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"))
推薦閱讀
- Raspberry Pi for Python Programmers Cookbook(Second Edition)
- Java應用與實戰
- Mobile Application Development:JavaScript Frameworks
- C++程序設計(第3版)
- Developing Mobile Web ArcGIS Applications
- 程序員面試筆試寶典
- HTML5 Mobile Development Cookbook
- Hands-On JavaScript High Performance
- C語言程序設計
- Learning Unreal Engine Android Game Development
- Kubernetes源碼剖析
- SFML Game Development
- Responsive Web Design with jQuery
- VMware vSphere 5.5 Cookbook
- Mastering Machine Learning with R