I have two strings:
lp.NameA string returned from a backend server database contained in the class
LocalPlayer:public class LocalPlayer { public string Name; }playerNameA local string variable.
Here is the code block I am running:
private void UpdatePlayer()
{
bool localPlayerFound = false;
if (player != null)
{
if (player.localPlayers != null)
{
if (player.localPlayers.Count > 0)
{
foreach (LocalPlayer lp in player.localPlayers)
{
Debug.Log("Name =" + lp.Name + " Length " + lp.Name.Length + " Bytes " + string.Join(",", System.Text.Encoding.Unicode.GetBytes(lp.Name)));
Debug.Log("Name =" + playerName + " Length " + playerName.Length + " Bytes " + string.Join(",", System.Text.Encoding.Unicode.GetBytes(playerName)));
bool areEqual = string.Equals(lp.Name.Trim(), playerName.Trim());
Debug.Log(areEqual);
if (areEqual)
{
localPlayerFound = true;
// Fill out Player stats
}
}
}
}
}
if (localPlayerFound == false) // NO players yet in Local Database - Create a new one
{
AddNewLocalPlayer();
}
}
The output of the Debug statements are:
After a few suggestions I added Length and encoding to the debug statements. Here is what comes up in the debug statements.
Name =Flash Length 5 Bytes 70,0,108,0,97,0,115,0,104,0
Name =Flash Length 6 Bytes 70,0,108,0,97,0,115,0,104,0,11,32
False
If trim doesn't remove the hidden characters, what can I use?
It says that The output confirms that byte 11 corresponds to the vertical tab character, and byte 32 corresponds to the space character.
Thanks
Consider using RegEx which would offer a highly customizable fallback option. Here are three basic extensions to try for starters, any of which work on the specific case you show.
Console mock with the provided test bytes shown in the post.