Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i find certain letters in a string?

Asked by 8 years ago

Lets say I have two values, "Baby", and "Dog". What I want to do is find both of those strings in one name in lighting, as in "Baby Dog". The thing is, I don't know how to find certain letters in strings to be able to do this.

2
You can use find function. string.find(originalstring,'Baby') or originalstring:find('Baby') M39a9am3R 3210 — 8y

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

You just use string.match. It matches strings. If it finds a match, it returns that match; otherwise it returns nil.

local str = "Baby Dog"
print( str:match("Baby") ) --> Baby
print( str:match("qwerty") ) --> nil

You can also use string patterns for less specific matching.

Ad

Answer this question