I'm currently trying to load a simple text file and filter it by a certain string. In the text file I'm using a new line for each value and sometimes use a "--" to make things easier to read for me when viewing the .txt-file.
Now, when I load the file and split it by new lines I end up with a list of substrings, each representing a value I need. Plus, all the "seperators" I put into the file.
My goal is to clean the list from all the seperators and basically just remove them from the list. However, RemoveAll does not work and I found out that the strings containing "--" are not really "--", but something else, because using string.Equals("--") fails on them.
Somewhere when reading the data or splitting it, something happened to those parts, but I can't figure out what's happening.
Here's the code:
void Awake() {
_fileLines = new List<string>();
TextAsset txt = Resources.Load<TextAsset>("SubjectPages/test");
_fileLines = new List<string>();
_fileLines = txt.text.Split(new string[] { "\n" }, System.StringSplitOptions.None).ToList<string>();
_fileLines.RemoveAll(x => ((string)x) == "");
_fileLines.RemoveAll(x => ((string)x) == "--");
for (int i = 0; i < _fileLines.Count; i++) {
Debug.Log(_fileLines[i] + " | " + (_fileLines[i].Equals("--")) + " | " + (_fileLines[i] == "--"));
}
}
Removing empty lines with RemoveAll seems to work fine.