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

x
?
Solved

comparing Strings

Posted on 2006-10-24
6
Medium Priority
?
251 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
[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 64

Expert Comment

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

Author Comment

by:sherrick123
ID: 17798612
2005
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 64

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

670 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