Looking to see best way to compare strings.
local EVENT_MESSAGE = “Good Washing Everyone”
if (string.starts(EVENT_MESSAGE,“Good”)) then
return true
else
return false
end
But I do not think the function string.starts works in Vera. I can use string.len and string.format, but does not look like “starts” or “ends” function work.
Solar2D lets you build games/apps for all major platforms including iOS, Android, Kindle, Apple TV, Android TV, macOS, and Windows. Get the free toolset!
Does anyone know best way to see if two strings are the same or contain a word?
akbooer
January 14, 2019, 7:45pm
#2
For pure equality, just use the == operator.
For partial matches, use string.match() or string.find(), see
https://www.lua.org/manual/5.1/manual.html#pdf-string.match
You’ll need to master Lua pattern strings (really a subset of regular expressions.)
https://www.lua.org/manual/5.1/manual.html#pdf-string.upper
Thanks I will use this.
local EVENT_MESSAGE = “Good Morning”
local RESULT = string.match (EVENT_MESSAGE, “Morning” )
if ( RESULT == nil) then
return “Did not Find”
else
return “Found result”
end
Was thinking we could use more of lua and this seems common, but I guess not.
akbooer
January 14, 2019, 9:05pm
#4
Sorry, don’t understand. This is all Lua.
My goal was to use a standard lua function like this:
string.starts()
But that function does not appear to work or is not available in vera lua. When I run it it does not work and gives error.
Goal was to have function that returned true or false. Based on your comments I decided to use another function that is in vara lua.
Using the string.match() function, I can achieve same end goal. Look at string and see if a sub string exist with in it.
From what I can tell, vera lua is not 100% same as core lua. Not big deal, but the reason I posted question.
rigpapa
January 14, 2019, 11:59pm
#6
[quote=“kyle.dawson, post:5, topic:200434”]My goal was to use a standard lua function like this:
string.starts()
But that function does not appear to work or is not available in vera lua. When I run it it does not work and gives error.
Goal was to have function that returned true or false. Based on your comments I decided to use another function that is in vara lua.
Using the string.match() function, I can achieve same end goal. Look at string and see if a sub string exist with in it.
From what I can tell, vera lua is not 100% same as core lua. Not big deal, but the reason I posted question.[/quote]
I think what akbooer is trying to convey is that Vera Lua is real Lua (Lua 5.1), and string.starts() is not real Lua, it’s a Corona extension.
Oh, I see now. Good point. Did not see that before. Thanks for clarification.