Solved

comparing Strings

Posted on 2006-10-24
6
247 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 63

Expert Comment

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

Author Comment

by:sherrick123
ID: 17798612
2005
0
 
LVL 63

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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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 63

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

829 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