String.len
Signature
String:lenDescription
len allows to receive the byte length of a Tea string.Example
const s = "Hello, world!"
print(s.len) // 13
print("Exploding Kittens!".len) // 19
String.upper
Signature
function String:upper()Description
upper method produces a new Tea string copy of the original string with all its characters uppercase.Example
var str = "Hello, world!"
str = my_string.upper()
print(str) // "HELLO, WORLD!"
String.lower
Signature
function String:lower()Description
lower method produces a new Tea string copy of the original string with all its characters lowercase.Example
var str = "Hello, world!"
str = my_string.lower()
print(str) // "hello, world!"
String.reverse
Signature
function String:reverse()Description
reverse method produces a new Tea string copy of the original string with its characters reversed in order.Example
const str = "Hello, world!"
str = str.reverse()
print(str) // "!dlrow ,olleH"
String.split
Signature
function String:split(separator='', maxsplit=nil)Description
split methodParameters
separator- A string that specified the character(s) to use as the separator. If
separatoris not specified, the string is split on any white space" ". maxsplit- An optional number that specified the maximum number of splits allowed to perform. If
maxsplitis not specified, the string is split into as many sub-strings as possible.
Returns
The method returns a list of string created by splitting the original string at each occurrence of the specified separator value, maxsplit times.
Example
var str = "Hello, world! How are you today?"
str = str.split()
print(my_list) // ["Hello,", "world!", "How", "are", "you", "today?"]
String.contains
Signature
function String:contains(substr)Description
contains method checks whether the specified string is found within the original string.Parameters
substring- The string to search for within the original string.
Returns
The method returns true if the substring is found within the original string, or false otherwise.
Example
var str = "Hello, world!"
var result = str.contains("world")
print(result) // true
result = str.contains("foo")
print(result) // false
String.startswith
Signature
function String:startswith(prefix)Description
startswith method checks whether the original string starts with a specified string sequence.Parameters
prefix- The string to search for at the start of the original string.
Returns
The method returns true if the original string starts with prefix, and false otherwise.
Example
var str = "Hello, world!"
var res = str.startswith("Hello")
print(result) // true
res = str.startswith("foo")
print(result) // false
String.endswith
Signature
function String:endswith(suffix)Description
endswith method checks whether the original string ends with a specified string sequence.Parameters
suffix- The string to search for at the end of the original string.
Returns
The method returns true if the original string ends with suffix, and false otherwise.
Example
var str = "Hello, world!"
var res = str.endswith("world!")
print(res) // true
res = str.endswith("foo")
print(res) // false
String.leftstrip
Signature
function String:leftstrip()Description
leftstrip strips the original string of any leading white spaces.Returns
The method returns a copy of the original string with leading white space removed.
Example
var str = " Hello, world!"
str = str.leftstrip()
print(str) // "Hello, world!"
String.rightstrip
Signature
function String:rightstrip()Description
rightstrip method strips the original string of any trailing white spaces.Returns
The method returns a copy of the original string with all trailing white spaces removed.
Example
var str = "Hello, world! "
str = str.rightstrip()
print(str) // "Hello, world!"
String.strip
Signature
function String:strip()Description
strip method strips the original string of any leading and trailing white spaces.Returns
The method returns a copy of the original string with all its trailing and leading white spaces removed.
Example
var str = " Hello, world! "
str = my_string.strip()
print(str) // "Hello, world!"
String.count
Signature
function String:count(substr)Description
count method counts the number of occurrences of a specified string string within the original string.Parameters
substr- The string to search for within the original string.
Returns
The method returns the number of occurrences of substr within the original string.
Example
var str = "Hello, world! Hello, world!"
var res = str.count("Hello")
print(res) // 2
res = str.count("foo")
print(res) // 0
String.find
Signature
function String:find(substr)Description
find method finds the index of the first occurrence of a specified string within the original string.Parameters
substr- The string to search for within the original string.
Returns
The method returns the index of the first occurrence of substr within the original string, or -1 if the string if not found.
Example
var str = "Hello, world!"
var res = str.find("world")
print(res) // 7
res = str.find("foo")
print(res) // -1
String.replace
Signature
function String:replace(oldstring, newstring)Description
replace method replaces all occurrences found of a specified string from the original string with a different string sequence.Parameters
oldstring- The old string occurrence present within the original string.
newstring- The string to replace
oldstringwith in the new string.
Returns
The method returns a copy of the original string with all occurrences of oldstring replaced with newstring. If no occurrences have been found, the returned string is exactly the same original string value.