StringSplitOptions.RemoveEmptyEntries - Unknown identifier

Hello, I am using a String to save scores for my levels (PlayerPrefs). As PlayerPrefs doesn’t work with arrays, I just convert all of these into one String to this form:
“LVL1score;LVL2score;LVL3score;” and so on.

However, when I try loading from it and spliting it with this code:

prefText = PlayerPrefs.GetString("Levels");
var lvlTexts = prefText.Split(";"[0], StringSplitOptions.RemoveEmptyEntries);
var j : int = 0;
for (lvlInfo in lvlTexts) {
    levels[j].levelUnlocked = (lvlInfo[0] == "Y") ? true : false;
    levels[j].levelFinished = (lvlInfo[1] == "Y") ? true : false;
    levels[j].levelScore = int.Parse(lvlInfo.Substring(2, lvlInfo.length - 2));
    j++;
}

i get an error "Unknown identifier ‘StringSplitOptions’ (i need it to not include “” String after last semicolon). I have tried using import System in the beginning of script, i have tried using System.StringSplitOptions.RemoveEmptyEntries, but nothing work. I have decided to just remove last character in String, which works, but I would still like to understand, why the code above doesn’t work. Thanks in advance.

The .Split function you are using does not take StringSplitOptions as a parameter. So without System. in front you get the regular Unknown Identifier, but with it you would get Invalid Arguments.

When you supply the char to split with directly then you are using the .Split function which only takes an optional number of char values to split with.

To use the .Split function which can take the StringSplitOptions you have to supply your char values as an array:

string stringToSplit = "";
char[] splitters = { ';' };
string[] splittedString = stringToSplit.Split(splitters, System.StringSplitOptions.RemoveEmptyEntries);

Unity works with a (very, very) old version of Mono, for somewhat esoteric reasons (you can search around if you are curious). This means, among other things, that some methods that’s available in modern versions of C# - either .NET or modern Mono - are not available in Unity.

My guess is that StringSplitOptions.RemoveEmptyEntries is one of those. Which means you have to do this the old fashioned way: either ignoring empty strings in your loop, or removing them beforehand.