Is it possible to specify a certain part of a string?

So, let’s say I have this string.

local String = "dfhqfqu9fhHelloigjruig"

I want to print the part of the string which has the word ‘Hello’, and ignore all of the other parts of the string.

Is this possible?

2 Likes

I’m pretty sure you can use string.match() for this like so:

string.match(String, "Hello")
3 Likes

Yes, you can use String.match() function like Sonde mentioned or String.find() if you want to locate where a specific words starts and ends in a string. Also if that word is consistently in a particular place, you can use String.sub(“dfhqfqu9fhHelloigjruig”, 10, 14) - assuming you know the position.

3 Likes

Either you are looking for string.match which is below or you are trying to find where it says that which is, but you can also use it just to figure out if it was sent with this below

string.find(String,"Hello")
-- Will return tuple of two numbers, the starting number is which letter starts at
-- and the ending letter in the string, e.g "Hello World" is 1,5

local stringStart, stringEnd = string.find(String,"Hello")
print(stringStart, stringEnd)
if string.find(String,"Hello") ~= nil then
-- Code
end
3 Likes

Thank you guys for the help! I appreciate it.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.