My problem as simple as it may seem has taken me a while that I hope to spare you with this answer.
The great mystery about these comparisons and looking for string inside another string or whatever you want to call it, was due to a character known as Cruz Lorena or Cruz de Lorena . Character this "invisible" to the eyes when contained in a string inside Visual Studio.
First I discovered that there was something wrong comparing the size between the strings that were "identical" visually speaking, but distinct in their size. All I had to do was check the property Lenght of each of the strings.
From there, I copied both strings and pasted them into one MD5 encryption online to see if in fact the result of the encryption would be different and by luck pasting in the text field to be encrypted, the "invisible" character appeared.
Even after I discovered the character the only thing I couldn’t figure out is why Contains did not work since this character was next to the name, as in the example below:
var texto = "qualquer coisa relacionado à Gustavo"; //esse carácter é invisível aqui também.
texto.Contains("Gustavo"); //Sempre retornava false
So, right after I discovered the existence of this character, I tried the obvious, the .Replace()! For, when pasting it into the place indicating the char that should be replaced in the VS was something like:
texto.Replace("",""); //pois é ele ainda era invisível aqui também.
And of course VS would complain.
So I thought, because not only do I recover the alphanumeric characters that I need in this case (delete the different characters from that), then I applied the following Regex to my string.
Regex rgx = new Regex("[^a-zA-Z0-9 -]");
texto = rgx.Replace(texto, "");
and made him disappear from the equation!
I don’t know what the chances of that happening to you, too, so obviously I gave a simpler example of what really happened to me, but this text comes through an api consumed by me, and it’s something totally unexpected by any application that has never been through so I believe. Even the fact that I have not found any post or blog talking about this case in specific and the google searches did not return any content that would help in solving my problem. And for this reason I decided to share this experience with you, I hope it helps!
The
nome
insidelinha
are equally written (upper and lower case letters)?– igventurelli
Put real code that we can test with values where the problem is. Here’s how to make a [mcve].
– Maniero
Try the method
equals
line.equals(name) to see what comes back– R.Santos
Yes, I published the solution. The problem a little more complex. I have worked for a while with development but turns and moves we end up being caught by some prank of the development world. If you find it interesting read my reply and thank you for Help!
– Gustavo Pisani