Jun 24, 2014 #1 R rkt_167 Junior Member level 1 Joined Aug 9, 2013 Messages 19 Helped 3 Reputation 6 Reaction score 3 Trophy points 3 Activity points 163 hi all, I am comparing two strings: Code C# - [expand]1 bool d = (String.Equals(ethernetHeader.Source,staticForm.textBox1.Text.ToString())); this statement is always false even in console both are same as below.. ethernetHeader.Source=00:25:64:4F:219 textBox1.Text=00:25:64:4F:219 any possible reason?? thanks,
hi all, I am comparing two strings: Code C# - [expand]1 bool d = (String.Equals(ethernetHeader.Source,staticForm.textBox1.Text.ToString())); this statement is always false even in console both are same as below.. ethernetHeader.Source=00:25:64:4F:219 textBox1.Text=00:25:64:4F:219 any possible reason?? thanks,
Jun 24, 2014 #2 H horace1 Advanced Member level 5 Joined Nov 18, 2008 Messages 2,118 Helped 596 Reputation 1,188 Reaction score 571 Trophy points 1,393 Location Norwich, UK Activity points 13,063 should work - could you have spaces or a newline in one of the strings? try printing the strings e.g. Code: Console.WriteLine(" '{0}' '{1}' {2}\n", ethernetHeader.Source, staticForm.textBox1.Text.ToString(), d); you should then see if the strings are identical also you don't require the ToSting() in staticForm.textBox1.Text.ToString() staticForm.textBox1.Text returns a string
should work - could you have spaces or a newline in one of the strings? try printing the strings e.g. Code: Console.WriteLine(" '{0}' '{1}' {2}\n", ethernetHeader.Source, staticForm.textBox1.Text.ToString(), d); you should then see if the strings are identical also you don't require the ToSting() in staticForm.textBox1.Text.ToString() staticForm.textBox1.Text returns a string
Jun 25, 2014 #3 R rkt_167 Junior Member level 1 Joined Aug 9, 2013 Messages 19 Helped 3 Reputation 6 Reaction score 3 Trophy points 3 Activity points 163 thanks horace1, Code: bool d = (String.Equals(ethernetHeader.Source.ToString(), staticForm.textBox1.Text.Trim())); I used Trim() and now it is working fine.
thanks horace1, Code: bool d = (String.Equals(ethernetHeader.Source.ToString(), staticForm.textBox1.Text.Trim())); I used Trim() and now it is working fine.