Solved

Arrays to check duplicates in vb.net

Posted on 2016-07-25
8
37 Views
Last Modified: 2016-07-25
Hi,

How to check if array has a string.Three checks on Uppercase,mixed case and lowercase.

 If IsDBNull(SQLdr(StrCol1)) = False Then
                    StrColval1 = SQLdr(StrCol1).ToString
                    StrColval1 = StrColval1.Trim
                    If StrColval1 <> String.Empty Then
                        If Not (Arr1.Contains(StrColval1)) Then
                            If Not Arr1.Contains(StrColval1.ToLower) Then
                                Arr1.Add(StrColval1)
                            End If
                        End If
                        End If
                End If

Any better way of doing this?
0
Comment
Question by:RIAS
  • 3
  • 3
  • 2
8 Comments
 
LVL 9

Accepted Solution

by:
Paweł earned 500 total points
ID: 41727511
yes use the following
https://msdn.microsoft.com/en-us/library/zkcaxw5y(v=vs.110).aspx

loop through your array and just compare once

Dim myString =""
For Each lstString As String In lst
    if(String.Compare(myString, lstString, true))
    'found string

   end if
Next
0
 

Author Comment

by:RIAS
ID: 41727514
Paweł,
Cheers! Any suggestion how can i use it my code...
0
 
LVL 9

Expert Comment

by:Paweł
ID: 41727515
check the comment again, i added a snippet, be weary of the syntax, it's been a long time since i've used Visual Basic.
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Closing Comment

by:RIAS
ID: 41727537
Thanks!
0
 
LVL 14

Expert Comment

by:wsh2
ID: 41727540
Air-coded:
 
Dim strFind as string = "abc"
Dim str1st As String = "ABCd, abcd, AbCd)
Dim str2nd As String
'
str2nd = str1st.Upper.Replace(strFind.Upper, "")
MsgBox _
   ((str1st.Length - str2nd.Length) / str1st.Length).ToString & " occurences found"
1
 
LVL 14

Expert Comment

by:wsh2
ID: 41727541
Air-coded:
 
Dim strFind as string = "abc"
Dim str1st As String = "ABCd, abcd, AbCd)
Dim str2nd As String
'
str2nd = str1st.Upper.Replace(strFind.Upper, "")
MsgBox _
   ((str1st.Length - str2nd.Length) / str1st.Length).ToString & " Occurences Found"
1
 
LVL 14

Expert Comment

by:wsh2
ID: 41727542
Correction:

Dim strFind as string = "abc"
Dim str1st As String = "ABCd, abcd, AbCd)
Dim str2nd As String
'
If strFind.Length > 0 Then
    str2nd = str1st.Upper.Replace(strFind.Upper, "")
    MsgBox _
       ((str1st.Length - str2nd.Length) / strFind.Length).ToString & " Occurences Found"
End If
1
 

Author Comment

by:RIAS
ID: 41727631
Cheers!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…

830 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