Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Searching A String, For A Match From Another String


Searching A String, For A Match From Another String

Author
Message
mangopalaya
mangopalaya
Forum God
Forum God (750 reputation)Forum God (750 reputation)Forum God (750 reputation)Forum God (750 reputation)Forum God (750 reputation)Forum God (750 reputation)Forum God (750 reputation)Forum God (750 reputation)Forum God (750 reputation)

Group: Forum Members
Posts: 2, Visits: 6
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
Mobius
Mobius
Forum God
Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)Forum God (103K reputation)

Group: Forum Members
Posts: 632, Visits: 1K
Check out regular expressions.





-Mobius

paul daniel
paul daniel
Forum God
Forum God (5K reputation)Forum God (5K reputation)Forum God (5K reputation)Forum God (5K reputation)Forum God (5K reputation)Forum God (5K reputation)Forum God (5K reputation)Forum God (5K reputation)Forum God (5K reputation)

Group: Forum Members
Posts: 19, Visits: 20
Refer this link



http://www.vb6.us/tutorials/vb6-string-functions



http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingWithStringsP311232005021723AM/WorkingWithStringsP3.aspx

.NET Application Development | C# Development
Edited
2/1/2010 by paul daniel
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search