Solved

comparing Strings

Posted on 2006-10-24
6
244 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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 …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 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

21 Experts available now in Live!

Get 1:1 Help Now