So what I have is two strings.. Each string is a comma seperated value of two digit states. Like this String 1: "NV,CA,AZ" String 2: "ND,HI,CA" What I need to do, is write some C# to check string 2, for a match in string 1. Meaning, If a state is listed in String 1, it should not appear in String 2. I have used "foreach" statements, but only for list boxes. I can seperate the strings, but am having an issue writing the code to compare the two. Here's what I got so far, it will check the first thing in each list, but will not go onto the second or third? How can I change the int inside String1[0] to +1 for every item in it's list? Edit: It would be awesome if the code could find the position of the match in the second string, and remove it. So if it finds CA from String1, in String2, it would remove it from String2. 1. string[] String1 = LabelAllStates.Text.Split(new char[] { ',' }); 2. string[] String2 = LabelAllCountyStates.Text.Split(new char[] { ',' }); 3. 4. foreach (String myCountyList in String1) 5. { 6. if (String1[0] == String2[0]) 7. { 8. // Detected a match, therefore I fail validation 9. } 10. else 11. { 12. // No match found! Good job! 13. } 14. }
Best diet pills I Weight loss surgery
|