Problems identifying new line character in unity

Hi,

I’m trying to build an interpreter in unity to process input from the player.

I’m struggling with recognising a new line character to create a token also for that.


I usually used Regex.Unescape but this only works with strings, not with characters. What do you suggest?


Right now this solution isn’t giving me any results:

char character = InputString[current];   
if (character == '

')
{
TempToken = new { Id = “newline”, value = “newline”, };
Tokens.Add(TempToken);
current++;
Debug.Log(“found a new line”);
continue;
}

As @Snepple suggested, I tried looking for the asci value.
Considering also the suggestion from @icehex (which got deleted) I looked at both the character for “New Line” (10) and Carriage Return (13).

    if ((int)character == 10 || (int)character == 13) 
    {
        Token = new { Id = "newline", value = "newline", };
        Tokens.Add(Token);
        current++;
        Debug.Log("found a new line");
        continue;
    }

This, however, isn’t giving me any results.
I tried logging the asci characters of the input string and typing just the return key, this is the code and the output I get:

    foreach (char c in InputString)
    {
        Debug.Log((int)c);
    }

Output: 10 32 10 32

According to ASCII tables, “10” is for a new line character while “32” for a space.
But it is not recognised by the if statement.


I guess the character is jut being skipped somewhere. I never see the syntax error that I have put at the end of the loop and should report a character that hasn’t met any of the conditions in the if statements before (IsLetter, IsNumber etc).


This is the code I use to get the character from the string

  char character = InputString[current];