Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.Net  How to check a string against many other strings

Posted on 2013-01-19
6
Medium Priority
?
327 Views
Last Modified: 2013-01-19
Hi Experts.   I have a simple string "abc" that must be matched against a list of about 350 other strings that are split  into about 20 groups.  Some strings within a group are always the same and will be hardcoded but some are dynamic and must be supplied by the user.
If a match is found then I need to increment a number by one to show that the string matched something in that group.

So  "abc" is matched against

Group One
hsg
usy


Group Two
osy
pau

Group Three
abc
ahz


And so group three would be incremented by 1

I though I could do "If Then ElseIf"  but with the user defined values it got lengthy and complicated.   Whats the correct way to do this??   Any help appreciated.
0
Comment
Question by:PNRT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:sognoct
ID: 38796187
which framework ?
0
 
LVL 2

Author Comment

by:PNRT
ID: 38796205
Currently 2 and would prefer to stay there but could go to 4 if there was good reason
Thanks for the reply
0
 
LVL 9

Expert Comment

by:sognoct
ID: 38796443
I don't know how you define groups, so I can imagine it is some kind of object. I would define a group like this
public class groups 
public str as list(of string) = nothing 
public matched as int32 = 0 

Open in new window


then you can define a list of groups and search the string inside each group like this :
dim p as list(of groups) = new list(of groups)

now you can populate elements of the list and when you populate all of 350 groups
can search with a simple for each like this
For Each el As groups In groups
 if el.str.contains("abc") then el.matched +=1 
Next

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:PNRT
ID: 38796513
Thanks for the help, this sounds exactly what I'm looking for but I'm struggling.   Firstly I had defined the groups into lists of strings and would like to keep this as it was quite lengthy

I created a new class with

Public Class Groups
    Public str As List(Of String) = Nothing
    Public matched As Int32 = 0
End Class

Then when I use

        Dim p As List(Of Groups) = New List(Of Groups)
        For Each el As Groups In Groups
            If el.str.Contains("abc") Then el.matched += 1
        Next

I get the error ......   Groups' is a type and cannot be used as an expression
0
 
LVL 9

Accepted Solution

by:
sognoct earned 2000 total points
ID: 38796537
sorry I did not debug was just an example on the fly ... here is a working code

Public Class Groups
    Public str As New List(Of String)
    Public matched As Int32 = 0

    Public Sub New(ByVal str2split As String)
      For i As Int32 = 0 To (str2split.Length / 3) - 1
        str.Add(str2split.Substring(i * 3, 3))
      Next
    End Sub

  End Class

    Dim sp As New List(Of Groups)
    sp.Add(New Groups("hsgusytstaab"))
    sp.Add(New Groups("osypautfr"))
    sp.Add(New Groups("abcahz"))

    For Each el As Groups In sp
      If el.str.Contains("abc") Then
        el.matched += 1
      End If
    Next

Open in new window

0
 
LVL 2

Author Closing Comment

by:PNRT
ID: 38796552
Worked Great, many thanks
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question