Comparing two similar strings, but the result is negative always

I am reading data from a text file.
The data is stored in text file as,

1,A
2,B
3,C
4,A
5,B
and so on…

following is the code that I am using…

string[] str = Correct_Ans.text.Split("\n".ToCharArray());
for (int i = 0; i < 10; i++) {
                    
            string[] qAns = str[i].Split(',');
            
            if(qAns[1] == "A") {
                GameConstants.AnswerArray[i+1] = 1;
                
            }
            else if(qAns[1] == "B") 
                GameConstants.AnswerArray[i+1] = 2;
            else
                GameConstants.AnswerArray[i+1] = 3;
            Debug.Log("Ans Array = " + GameConstants.AnswerArray[i+1] );
            
            Debug.Log("qAns[1] = " + qAns[1] + "Type = "+qAns[1].GetType());
        }

The Debug stmt
Debug.Log("qAns[1] = " + qAns[1] + "Type = "+qAns[1].GetType());
gives proper output ie:
qAns[1] = C Type = System.String

but Debug.Log("Ans Array = " + GameConstants.AnswerArray[i+1] );
gives output as : Ans Array = 3

It always executes the else statement.

I have used all possible functions for comparing these two strings but still the output is same…

Please help.

Regards,
Amit.

didnt look too closely at ur code but i did see one thing that got me a while back… its \r\n so you very well might be comparing A to A\r

Gosh…

Yes I was comparing A to A\n … :slight_smile:

Thanks for the help.

I used

qAns[1]=qAns[1].Replace("\r", string.Empty).Replace("\n", string.Empty);

and it works perfectly fine now… :slight_smile: