- Home /
Parsing and new lines
Hello everyone.
I'm creating a custom class to parse my own level files. To make it, I'm treating the text file string as an array of char, calling string[i] to get a char from the array. Although it's working mostly fine I'm having problems into detecting new lines, as I can't tell wether the char I'm reading is a new line character or not. I was trying to do:
if(string_file[i] != System.Environment.NewLine) {
//Some code here
}
The problem is System.Environment.NewLine is a String, and I can't seem to get to treat it like a single character. I've already tried to check with System.Environment.NewLine[0] as well but I'm not getting the desired results. I might be missing something here, any help would be much appreciated.
Thank you very much
Answer by Golan2781 · Jan 27, 2013 at 11:09 PM
Special characters usually are made up of a reserved character plus an identifier. E.g. a tab is \\t and a newline is \\n. So simply checking for a single character will never be sufficient to detect them.
I would suggest using actual string methods, by the way. For example, string splitting at the newline symbol could safe you a lot of time. I doubt it'd have a negative impact over manually parsing text character by character.
Oh, I see, so I wasn't looking at the right place. With a few adjustments i'll have this working, thank you very much!
And, by the way, I didn't really understand what you meant in splitting at the newline symbol. Could you explain what does it mean? I'd like to know any method which might prove more useful than $$anonymous$$e.
Your answer
Follow this Question
Related Questions
Inconsistent Line Endings using Asset Server across platforms 0 Answers
how to implement character mechanics like flappy bird 1 Answer
Char class issues 0 Answers
Char To Texture 1 Answer