I’m just comparing two strings, searching for an object, and can’t get a match to read ‘true.’ I’m pretty sure I’m not making a spelling mistake. Here’s the code snippet:
Debug.Log("The name of this game object is:\""+gameObject.name+"\"");
Debug.Log("The name of the parent path is:\""+detailInfo.parentPath+"\"");
if(gameObject.name == detailInfo.parentPath) print ("THEY ARE THE SAME!");
else print("They do not match.");
string goName = gameObject.name;
string parentName = detailInfo.parentPath;
Debug.Log("The name of this game object is:\""+goName+"\"");
Debug.Log("The name of the parent path is:\""+parentName+"\"");
if(goName == parentName) print ("THEY ARE THE SAME!");
else print("They do not match.");
And here is what we see in the Debug window (click on it to enlarge, sorry):
As you can see, the letters in the string are the same, they should match. I don’t know what’s going wrong.
Eric,
The offending character is code # 13, which is a line return.
To get the string I had read a .txt file from resources and split it something like this:
TextAsset myText = Resources.Load(filePath, typeof(TextAsset)) as TextAsset;
string text = myText.text;
string[] line = text.Split( '\n' );
// little did I know that in addition to the newline there was a \r in there!!!
// had to add this line to get rid of the line return:
loadInfo.parentPath = line[0].Replace("\r","");
The split operation took away the newline, I had no idea there was also a line return in there as well.
I couldn’t use:
string[] line = text.Split("\n\r");
because it doesn’t like two characters in there. However, I found another expression that worked properly, with another using statement:
using System.Text.RegularExpressions;
string[] line = Regex.Split(text, "\r\n");
That took away both characters at once, solving the problem once and for all time, forever, done!