- Home /
Comparing a string to an array extraction?
Hoping someone can assist as I'm pulling my hair out. I've got an array that is pulling its lines from a text document where each line of text is an array entry, works no issue.
However I'm trying to compare a line from the array as text but it doesn't seem to be working.
string lineToCheck = textLines[currentLine];
print (lineToCheck);
if(lineToCheck=="thing"){
print ("well it worked I guess?");
}
lineToCheck is definitely appearing as thing but when compared just isn't picking up that it should be matching. Can someone point out where I'm going wrong?
I've also tried utilizing ToString but no dice.
I have looked around the net before resorting to bothering the community but I really just cannot figure out where my hiccup is.
Answer by OncaLupe · Dec 13, 2015 at 10:39 PM
My guess is there's a hidden character, like a newline, from when it was read in. You can use print(lineToCheck + "~" + lineToCheck.Length);
to see how long the saved string is, and if there is a newline in there it'd show up in the console with "~6" below "thing".
You can remove special characters like that with:
lineToCheck = lineToCheck.Replace("\n","");
You legend, that's the one - not sure how this didn't even occur to me.
The length check caught out the hidden character but not as a new line but carriage return ins$$anonymous$$d (ie. \r) ins$$anonymous$$d.
Thank you so much for your quick and helpful assistance!
Your answer
Follow this Question
Related Questions
how can i split a word to individual letters..?? 2 Answers
Array Slit String and Send NGUI text 0 Answers
Newbie Problem with Multidimensional Arrays in JavaScript 0 Answers
Split String into Arrays 1 Answer
Get JSON array object string value 2 Answers