C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » General »

Removing duplicate value and sort values in string array


Posted Date: 11 Sep 2008    Resource Type: Code Snippets    Category: General
Author: Shivashankar ChincholiMember Level: Gold    
Rating: 1 out of 5Points: 10



 
string[] str = new string[4];
str[0] = "shivu";
str[1] = "Anil";
str[2] = "shivu";
str[3] = "Anil";

str = RemoveDups(str, true);

The out put of array will be "shivu" and "Anil"


//Method for filtering the duplicates items..

public string[] RemoveDups(string[] items, bool sort)
{
string[] uniqueItems = null;

try
{
ArrayList noDups = new ArrayList();
for (int i = 0; i < items.Length; i++)
{
if (!noDups.Contains(items[i].Trim()))
{
noDups.Add(items[i].Trim());
}
}
if (sort) noDups.Sort(); //sorts list alphabetically
uniqueItems = new String[noDups.Count];
noDups.CopyTo(uniqueItems);
}
catch (Exception ex)
{
throw ex;
}
return uniqueItems;
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Filtering the duplicates items  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: YahooSearch Service
Previous Resource: How to find the Largest value in the table
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use