Solved

comparing Strings

Posted on 2006-10-24
6
245 Views
Last Modified: 2012-05-05
Hello All,
I need some help on where to start to compare ONE string to an array of strings and create ANOTHER ARRAY of matching strings following strings  they are both formated with a semicolon as a seperator BUT i want to compare the second string.  Here is an example
BTW they will be read in from an ascii file

String to use as what i want to compare everything against
on a note i won't know any comparison words.  Like for this example i wouldn't be able to put in wooden or door

WODOOR;wooden door

example of the different strings
10 02 01 ; solid wood door
10 03 04 ; hollow wood door
10 03 04 ; wooden laminent slider
10 25 04 ; window casement  <-- this should fail

I would want it to find the FIRST THREE examle BUT NOT THE LAST

Is their any hope??

Thanks
0
Comment
Question by:sherrick123
  • 3
  • 3
6 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 17798314
What version of .Net, 2003 or 2005?
0
 

Author Comment

by:sherrick123
ID: 17798612
2005
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 17798974
Hi sherrick123;

This solution uses Regular Expressions

Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click

        Dim TestData() As String = {"10 02 01 ; solid wood door", _
            "10 03 04 ; hollow wood door", "10 03 04 ; wooden laminent slider", _
            "10 25 04 ; window casement "}
        Dim FindWords As String = "WODOOR;wooden door"
        Dim MyFoundStrings() As String
        MyFoundStrings = DoesStringContain(FindWords, TestData)

    End Sub

    Private Function DoesStringContain(ByVal LookingFor As String, _
        ByVal LookingIn() As String) As String()

        Dim TempArray As New ArrayList

        LookingFor = LookingFor.Substring(LookingFor.IndexOf(";"c) + 1).Trim()
        LookingFor = Regex.Replace(LookingFor, "\s+", "`")
        LookingFor = Regex.Escape(LookingFor).Replace("`"c, "|")
        LookingFor = "\b" & Regex.Replace(LookingFor, "\s+", "|") & "\b"
        For Each str As String In LookingIn
            Dim ParseStr As String = str.Substring(str.IndexOf(";"c) + 1)
            If Regex.IsMatch(ParseStr, LookingFor, RegexOptions.IgnoreCase) Then
                TempArray.Add(str)
            End If
        Next

        Dim FoundStrings(TempArray.Count - 1) As String

        If TempArray.Count > 0 Then TempArray.CopyTo(FoundStrings)

        Return FoundStrings

    End Function
End Class


Fernando
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:sherrick123
ID: 17799162
Thanks Fernando
0
 

Author Comment

by:sherrick123
ID: 17799183
Question though what do the switches mean like the \b \s ??
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 17799198
They are Regular Expression meta-characters. The \b means that the next character start on a word boundary and the \s means a white space character.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now