How to find string in table non Case sensitive

Hello I hope it doesnt sounds too confusing basically I’ve just recently started using string.lower and I want to find the lowered string in the table for example:
I want to find by “thisistring” - “ThIsiSsTring” inside the table.

Thanks for help :)!

1 Like

You can use string.lower(string). Basically what this does is takes the string you plug into it and returns a lowered version of it. You can view more about strings here.

Example:

local My_Table = {thisisstring = 5} --Our table
local String = "ThIsiSsTring"

print(My_Table[string.lower(String)]) --Lower the string and print it

edit:
Just seen you said you started using string.lower() but I still hope this helps you.

3 Likes

Thank you, but I wanted to find by the lowered version the non lowered String.

1 Like

I dont really understand what you mean could you go into a little more detail please?

1 Like

I think he wants it so that if a user inputs “thisdog” it will find “tHiSdOg”. This is called String Manipulation.

1 Like

The best way to accomplish this, is to lower A.) the thing you’re searching for or B.) the condition. It’s the easiest and most efficient way to lowercase one or both so that they match since Roblox is case sensitive.

1 Like

Yes exactly this is what I want.

1 Like

Lanred_Dev is right then, you need to lowercase the thing you’re searching for, or at least the name. So for example, if I wanted to find a player based on UserInput…

for i, players in pairs(game.Players:GetChildren())
local playerName = string.lower(players.Name)
if playerName == string.lower(UserInput) then
print(players)
end
end

1 Like

Alright sorry I thought I can find the result by the lowercase version.

1 Like

I am sure you can, but there’s no reason to? You can still print out the uppercase version while searching for it by the lowercase version. For example:

Let’s say there’s a guy named “BoB” in my server… I made a variable called lowerName…

lowerName = string.lower(playersInMyServer)

So now, BoB’s name is now bob.

You then would say, ok… does bob == bob? Yes, it does. So print BoB.

2 Likes

hmm… that’s effectively what the example I provided is doing but we can do it that way also.

Instead of lowering an input/string, we can lower both to get a match.

local My_Table = {ThIsiSsTring = 5} --Our table
local Input = "ThisiSStRinG" --Not the same as the table name

for Key, Value in next, My_Table do
	if string.lower(Key) == string.lower(Input) then --Check if they are the same
		print(Value) --Print the value
	end
end
2 Likes

Yep, that’s what I said as well.

1 Like

Okay so I am sending the data through RemoteFunction right so.

I will Invoke Server with

RemoteFunction:InvokeServer(TextBox.Text:lower())

And now I want to find out if the data is inside the table in server script.

RemoteFunction.OnServerInvoke = function(player, TextBox)
local mytable {"IamString"}

if mytable[(TextBox)] then
print("I am valid member of the table")

I get it now but how do I implement it to this code?

1 Like

First issue, you’re missing an = on your mytable variable and it does not need to be inside the function as if you plan on having it add values you may not be able to access it and it will be reset every time the function/event is fired.

You’re also missing an end after your if statement and function, I am also assuming you have your RemoteFunction variable.

Now onto code.

local mytable = {"IamString"} --Table

RemoteFunction.OnServerInvoke = function(player, Text)
	for _, Value in pairs(mytable) do
		if string.lower(Value) == string.lower(Text) then --Check if they are the same
			print("text is in table :)") --Print if they are the same
		end
	end
end
2 Likes

You should store the table variable outside the Remote Function invoke connection:

local RemoteFunction = game:GetService("ReplicatedStorage").PathToRemoteFunction

local myTable = {"IamString"}

RemoteFunction.OnServerInvoke = function(player, text)
    for _, item in ipairs(myTable) do
        if item:lower() == text then
           return item
        end
    end

    return nil
end
2 Likes

Sorry I wrote it fast this is not the actual code it supposed to be example.

1 Like
invalid argument #1 to 'lower' (string expected, got table)
1 Like

Hmmm… I tested it and everything is working fine for me. Ill check one more time to make sure.

2 Likes

Replace your client code with:

RemoteFunction:InvokeServer(TextBox.Text) --Just removed the :lower()
1 Like

Make sense I will try it and let you know. :+1:

2 Likes