Click here to Skip to main content
13,096,760 members (95,145 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

23.2K views
5 bookmarked
Posted 4 Mar 2010

Remove duplicate entries from string array

, 4 Mar 2010
Rate this:
Please Sign up or sign in to vote.
This VS2008 or higher extension uses a LINQ statement to remove duplicate items from a string array but is not case sensitive, also you might like to leave the sort/order-by in the extension or remove it.ExampleDim Names() As String = {"Bob", "Mary", "bob", "Bob", "Jane", "Kevin",...
This VS2008 or higher extension uses a LINQ statement to remove duplicate items from a string array but is not case sensitive, also you might like to leave the sort/order-by in the extension or remove it.

Example
Dim Names() As String = {"Bob", "Mary", "bob", "Bob", "Jane", "Kevin", "Jane"}
Names = Names.RemoveDuplicates
For Each Name As String In Names
    Console.WriteLine(Name)
Next


Returns
bob
Bob
Jane
Kevin
Mary


Extension (place in code module)
<System.Diagnostics.DebuggerStepThrough()> _
<System.Runtime.CompilerServices.Extension()> _
Public Function RemoveDuplicates(ByVal sender As String()) As String()
    Return (From value In sender Select value Distinct Order By value).ToArray
End Function

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

karenpayne
Instructor / Trainer
United States United States
Microsoft MVP, Trouble shooter, component builder, and architect using Microsoft Visual Studio 2012/2013. Prior to VS .NET I developed solutions using Borland Delphi and before Delphi CA Clipper. I enjoy assisting others, sharing knowledge and learning from others. Outside of IT my passions are playing guitar and teaching self-defense. Currently a moderator for Microsoft Social forums in C#, VB.NET and Data binding forums. Lastly a MCC (Microsoft Community Contributor).

You may also be interested in...

Pro

Comments and Discussions

 
Generalmy vote of 1 Pin
Tweety4-Mar-10 7:51
memberTweety4-Mar-10 7:51 
GeneralRe: my vote of 1 Pin
GlimmerMan4-Mar-10 9:12
memberGlimmerMan4-Mar-10 9:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 4 Mar 2010
Article Copyright 2010 by karenpayne
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid