Assuming I have a line in lua:
> s = "abc123"
I want to get s1which is only the first character s or empty if sempty.
s1
s
I tried using
> s1 = s[1]
and
> s1 = s[0]
How can I get the first character without using external Lua libraries
but both return only nil.
nil
You can use string.sub()to get a substring of length 1:
string.sub()
> s = "abc123" > string.sub(s, 1, 1) a
This also works for empty lines:
> string.sub("", 1, 1) -- => ""
Source: https://habr.com/ru/post/1671711/More articles:capture group with extra substring - javaReact this.setState is not a function inside setTimeout - javascriptReading cookie value in asp.net core - cookiesReactJS: How to wrap a-select response in a shortcut field? - reactjsSplit an array depending on array values in Python - pythonUnable to shut down application version. Saves billing - google-app-enginereading a 64-bit volatile variable on corex-m3 - armWKWebView How to add cookies from HTTPCookieStorage - swift3Spring облако Zuul повторяет попытку, когда экземпляр отключен и переходит в другой доступный экземпляр - spring-cloudVS30063: you do not have access to https: // xxxxx-tfs - tfsAll Articles