Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

vb.net function

Posted on 2016-08-22
7
Medium Priority
?
90 Views
Last Modified: 2016-08-22
I would like to create a function that can compare two strings but not a normal compare:

Str1 "one two three"
Str2 "two one three"


it would check that the words in the string are identical (not case sensitive) but just in the wrong order. in the example here the output could be true

It needs to be efficient, maybe regex can do this or maybe vb.net has something a method for this.

I am in visual studio app
0
Comment
Question by:PeterBaileyUk
[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
7 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41764902
would this google project be what you are looking for?
https://code.google.com/p/google-diff-match-patch/
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 41764903
Better way could be create a string array and the compare the different values.
0
 

Author Comment

by:PeterBaileyUk
ID: 41764909
i dont want too resolve close matches which may happen with fuzzy stuff. only where the words are all the same but in a different order
0
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!

 

Author Comment

by:PeterBaileyUk
ID: 41764921
I found this on a thread but not sure if this will work as text and the logic is the wrong intersect

Function RevIntersect(arr1() As String, arr2() As String) As String()
    Dim sResult, aux As New List(Of String)()

    aux.AddRange(arr1)
    aux.AddRange(arr2)

    For Each elem As String In aux
        If (Not arr1.Contains(elem) OrElse Not Arr2.Contains(elem)) AndAlso _
        Not sResult.Contains(elem) Then  
            sResult.Add(elem)
        End If
    Next

    Return sResult.ToArray()
End Function

Open in new window

0
 
LVL 4

Expert Comment

by:Elizabeth Anderson
ID: 41765092
The .NET Framework provides several methods to compare the values of strings. So, it would be better to refer the link below -
https://msdn.microsoft.com/en-us/library/fbh501kz(v=vs.110).aspx
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 41765250
Hi Peter;

The following code snippet should do what you are looking for.
Dim str1 = "One tWo thRee".ToLower().Split(" "c)
Dim str2 = "twO oNe tHree".ToLower().Split(" "c)

If str1.All(Function(w1) str2.Contains(w1)) AndAlso str1.Length = str2.Length Then
    Console.WriteLine("All words win w1 are in w2")
Else
    Console.WriteLine("All words win w1 are NOT in w2")
End If

Open in new window

0
 

Author Closing Comment

by:PeterBaileyUk
ID: 41765579
I am going to play around with this. one thing i used to do in access was use the immediate window and push values into a module function. Does VS offer up a similar thing.? Oh and thank you, ive been slow to respond today.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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 …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 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