How to check if Object name starts with a certain letter?

Let’s say there’s is a frame, how can I check if it’s name starts with a certain letter?

For example if there are 2 frames, one called “Frame” other is “XFrame”, I wish to check if the object starts with X

Thanks.

local thisLetter = "a"
local name = obj.Name
if string.sub(name, 1, 1) == thisLetter then DO() end
3 Likes

Alternatively you can use string.match with the ^ pattern.

if name:match("^X") then --[[do something]] end
3 Likes

As another method, you can use string.find and see if that returns 1 as the starting position for the specified pattern:

local pattern = "X";
local name = "XFrame";

if (string.find(name, pattern) == 1) then
    --// Code
end
2 Likes