Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Substring/Lua/substring.lua
Normal file
24
Task/Substring/Lua/substring.lua
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
str = "abcdefghijklmnopqrstuvwxyz"
|
||||
n, m = 5, 15
|
||||
|
||||
print( string.sub( str, n, m ) ) -- efghijklmno
|
||||
print( string.sub( str, n, -1 ) ) -- efghijklmnopqrstuvwxyz
|
||||
print( string.sub( str, 1, -2 ) ) -- abcdefghijklmnopqrstuvwxy
|
||||
|
||||
pos = string.find( str, "i" )
|
||||
if pos ~= nil then print( string.sub( str, pos, pos+m ) ) end -- ijklmnopqrstuvwx
|
||||
|
||||
pos = string.find( str, "ijk" )
|
||||
if pos ~= nil then print( string.sub( str, pos, pos+m ) ) end-- ijklmnopqrstuvwx
|
||||
|
||||
-- Alternative (more modern) notation
|
||||
|
||||
print ( str:sub(n,m) ) -- efghijklmno
|
||||
print ( str:sub(n) ) -- efghijklmnopqrstuvwxyz
|
||||
print ( str:sub(1,-2) ) -- abcdefghijklmnopqrstuvwxy
|
||||
|
||||
pos = str:find "i"
|
||||
if pos then print (str:sub(pos,pos+m)) end -- ijklmnopqrstuvwx
|
||||
|
||||
pos = str:find "ijk"
|
||||
if pos then print (str:sub(pos,pos+m)) end d-- ijklmnopqrstuvwx
|
||||
Loading…
Add table
Add a link
Reference in a new issue