Thursday, May 7, 2015

How do i compare two strings and get the difference?

for example,

1)

s1 ="abc123"

s2 = "123"

strDiff = abc

2)

s1 = "abc123"

s2=""

strDiff = "abc123"


Based on your description, does the following code meet your requirements?

Using Except extension method to help do this, maybe there is a pure Linq way to achieve that.

  string s1 = "abc123 ";
            string s2 = "123";// or null
            char[] ss = s1.Except(s2).ToArray();
            string diff = new string(ss);
            MessageBox.Show(diff);

Best regards,

Kristin


We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.

No comments:

Post a Comment