Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I check the first 7 characters of a string, in a concise form?

If the word is Solider how would I do it,

Without doing this:

String = "soldier1"
Name = {"s", "o", "l", "i", "d", "e", "r")
for i, in String do
	if String[i] = Name[i] then
		print (..i.. "Ok")
-- This is rough I just done it now, this isn't supposed to be accurate.

1 answer

✓ Accepted answer

This uses the sub method of the string class.

Change s1 and s2 to whatever you want. Also change the num variable for the number of letters you want to check.

local s1 = "soldier1"
local s2 = "soldier"
local num = 7

if #s1 >= num and #s2 >= num then
	if s1:sub(1, num) == s2:sub(1, num)  then
		-- first {num} letters are the same
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.