Find all strings beginning with specified characters

Hi there, I’ve been trying to grab a list of all the PlayerPref strings that beging with “player”.
I found that:

var test = stringToSearch.IndexOf("player");

is a possible way of searching for strings, but i’m not entirely sure on the way in which this works.

or even substring method.

Anyone know how I can achieve this? Thanks - C

IndexOf returns the index of the first occurrence of the string you supply. A string in .Net is actually implemented as a character array, so when the method says “IndexOf”, it really means the index of the first character in the array that is the string, where the substring you’re searching for was first found.

So if you have this string:

string example = "This_string_says_player_in_it";

And you do this:

int index = example.IndexOf("player");

Then the variable index gets set to 17, because that’s the array index position of the ‘p’ in “player”. Because strings are really character arrays, you can actually index into a string directly, if you wanted to:

char indexedInto = example[17];

Is perfectly valid code, and sets the char indexedInto to the value ‘p’, because as we’ve previously shown, that’s the character found at index position 17.

That’s how strings and IndexOf works, anyway. I’m not sure how you could use that to obtain all PlayerPref strings that begin with the substring “player”. Are you using the method “PlayerPrefs.GetString()”?