if a string has certain letter(s) or number(s)

In my game, the player can enter a code to unlock certain things. I want they player to check to see if:

  • a) the code is one that can unlock something

  • b) if the code contains the letters to mean something

I don’t want to say if(string == string) cause each code is unique and can only be use once. Any ideas on how to do that would be appreciated.

You could use: string.contains(“what to look for”). Example (js):

private var TestString = "as3klkfjslgtke5tkt";

function CheckCode ()
	{
	if (TestString.Contains("3k"))
		{
		Debug.Log("Code Correct");
		//do whatever you need to do for 3k
		}
	}

EDIT: Alternative:

if (TestString.Contains("3") && (TestString.Contains("k"))

You could try a system where you use String.split on the string and look for a sequence of numbers or letters at certain places? Info here: String.Split Method (System) | Microsoft Learn

Have a look at all the methods available and see whats best.