How can I detect a string regardless of capitalization

  1. What do you want to achieve?
    So i have a ui with a TextBox that detects strings and depending on what is said it does a certain action

  2. What is the issue?
    I can only detect that arent capitalizated

  3. What solutions have you tried so far?
    I tried putting or “HELP” but that still wouldnt detect strings like “HeLP” etc

here is a video of this issue


(ignore the close, mini/maximise buttons i never fixed them)

here is part of the code that controls this, i have explained some parts just in case
textBox.Changed:Connect(function()
	textBox.Text = textBox.Text:sub(1,265)
end)

local function onTextBoxFocusLost(enterPressed, inputObject)
	if enterPressed then
		local help = "help" -- this is what is used to detect the strings saying help
		local _string = "" --detects spaces, removed for post cuz its very long
		if _string:match(textBox.Text) then --if the string contains ___ then
			local newFrame = script.Parent:Clone()
			newFrame.Parent = script.Parent.Parent
			newFrame.TextBox.Text = ""
			local newText = script.Parent.TextBoxDup
			newText.Visible = true
			newText.Text = textBox.Text
			textBox:CaptureFocus()
			textBox:Destroy()
		elseif help:match(textBox.Text) then --if the string contains ___ then
			local helpoutput = script.Parent.Parent.OutputHelp:Clone()
			helpoutput.Parent = script.Parent.Parent
			helpoutput.Visible = true
			local helplist = script.Parent.Parent.HelpList:Clone()
			helplist.Parent = script.Parent.Parent
			helplist.Visible = true
			local newFrame = script.Parent:Clone()
			newFrame.Parent = script.Parent.Parent
			newFrame.TextBox.Text = ""
			local newText = script.Parent.TextBoxDup
			newText.Visible = true
			newText.Text = textBox.Text
			textBox:CaptureFocus()
			textBox:Destroy()
1 Like

use string.lower(string)
or string.upper()

You just have to use string.lower it turns all the capital letters into their smaller form. You can also use string.upper but its less popular.

A little example

local function findThing(t, p)
  for i, v in t do
    if v:lower() == p then
      return i
    end
  end
end

local t = {
  'Help!'
}

print(findThing(t, 'help')) -- 1
1 Like

using string.lower gives me the same issue and string.upper is the same but only HELP works

this is kinda of confusing me lol, any chance that you can shove this into the script i showed above?

You may have to use string.lower on both strings to get it.

string1:lower() == string2:lower()

misunderstood string.lower and used it wrong, got it working now thanks