-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_string.lua
33 lines (26 loc) · 1.14 KB
/
example_string.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
local jsp = require("./jspower.lua")
local String = jsp.String
print(String.fromCharCode(97)) -- a
print(String.charAt("hello, world!",8)) -- w
print(String.charCodeAt("hello, world!",8)) -- 119
print(String.concat("hello,", " lua!")) -- hello, lua!
print(String.startsWith("banana", "ba")) -- true
print(String.endsWith("coconut", "nut")) -- true
print(String.includes("javascript", "vasc")) -- true
-- Alternatively, use jsp.extendLuaString()
jsp.extendLuaString()
-- After this, you can do:
print(("hello, world!"):charAt(8)) -- w
print(("hello,"):concat(" lua!")) -- hello, lua!
print(("banana"):startsWith("ba")) -- true
print(("coconut"):endsWith("nut")) -- true
print(("javascript"):includes("vasc")) -- true
local str = " trim me daddy "
print(str:trim()) -- "trim me daddy"
print(str:trimEnd()) -- " trim me daddy"
print(str:trimStart()) -- "trim me daddy "
local str = "Use the power of JS in Lua"
print(str:split(" ")) -- { "Use", "the", "power", "of", "JS", "in", "Lua" }
print(str:split("JS")) -- { "Use the power of ", " in Lua" }
print(str:toUpperCase()) -- USE THE POWER OF JS IN LUA
print(str:toLowerCase()) -- use the power of js in lua