If statement within the For-Loop is not working - Puzzled!

Hi all again,

I am having some puzzling issue with a If-statement within a For-loop. In brief, the script is supposed to, in the beginning, read a txt file into an array, and subsequently the If-statement-within-For-loop will identify the exact text needed and returns the value.

The txt file, named Language.txt, goes like this:

<English>
<Chinese>
<Malay>
<Tamil>

The script that I crafted goes like this:

function Start () {
    var fileName = "Language.txt";
    var sr = new StreamReader(Application.dataPath + "/" + fileName);
    var fileContents = sr.ReadToEnd();
    sr.Close();
    var Languages = fileContents.Split("
"[0]);

    var textNeeded = "<Malay>";
    for (var j : int = 0; j < Languages.Length; j++) {
        if (Languages[j] == textNeeded) {
            print(textNeeded);
        }
    }
}

Up till the part for the loop, the script has no problem, as if I insert a print(j) before the if-statement, all the j values (from 0 to 3) were returned in the debug console. And if I do print(Languages[j]) before (or after) the If-statement, all the Languages[j] are also returned. The one that is not working is the if-statement. Somehow it is not being activated (for lack of a better word).

I have look thru a number of questions/answers here in UnityAnswer, and it seems the script above is not too different from some of these questions/answers (e.g. like this, and theirs are working.). Am I missing something here?

Thanks in advance!

my guess is that your split function is leaving some white space characters before or after each element of Languages.

try:

var textNeeded = "<Malay>";    
 for (var j : int = 0; j < Languages.Length; j++) { 
      if (Languages[j].Trim() == textNeeded) {            
      print(textNeeded);       
   }  else {
  print("notmatched:'"+Languages[j].Trim()+"'");
  } 

}

if it doesnt work let us know what it prints