Question

Problem I currently have:

My server returns data back to the client, this includes a name. Now I want the client to grab this name and compare it. However for the past 3 hours I am stuck at this problem and I dont want to cheap fix around it.

My server returns a value and then a name, ex: random23454@NAMEHERE

I split the value using:

string[] values = returndata.Split('@');

And then I am doing:

if (textBox3.Text == values[1]) {
MessageBox.Show("equal");
}

However, the problem here is. I cant get it to be equal, I tried other methods but it just dont display equal.

What I have done:

Print textBox3.Text to a textbox and print values[1] to a other textbox and compared with my eye and mouse (Using invoke due to threading).

Used the .Trim() function Using the .ToString() on values[1] (Just for the hell of it) Assigned them both to a complete new string, trimmed them and compared them

Dragged the comparing outside the thread using:

this.Invoke((MethodInvoker)delegate()
                        {
                            outside(name);
                        });

and perform the same check.

My code:

 string returndata = System.Text.Encoding.ASCII.GetString(inStream);
                readData = "" + returndata;
                if (readData.Contains("@") && readData.Contains("random"))
                {


                    string[] values = returndata.Split('@');
                    string name = values[1].Trim();

                    if (textBox3.Text == name)
                    {
                        MessageBox.Show("true");
                    }
                    else
                    {
                        MessageBox.Show("false");
                        this.Invoke((MethodInvoker)delegate()
                        {
                            outside(name);
                        });

                    }

What else can I do? I just dont understand that it is not equal..

Thanks in advance.

Était-ce utile?

La solution

The data you're getting back from the server could be an array of bytes. Try converting the response to a string first before splitting. Also try printing the response (or the response's type) to console to see what you get before going any further.

Also make sure the length of each string is the same. Maybe give utf-8 a try instead of ASCII? Like so:

System.Text.Encoding.UTF8.GetString(inStream);

Autres conseils

string name = values[1].Trim();

I think you want values[2] here. The way I read the documentation for Split, the element at index 1 will be the (blank) separator indicator.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top