Solved

Arrays to check duplicates in vb.net

Posted on 2016-07-25
8
33 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 8

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 8

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
 

Author Closing Comment

by:RIAS
ID: 41727537
Thanks!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

947 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

19 Experts available now in Live!

Get 1:1 Help Now