Three asp.net methods are used to delete repeated array strings and array value instances.

Source: Internet
Author: User

Three asp tutorials. net Delete array duplicate strings and array value instances
I don't know. net, but today I still found three asp.net tutorial Instance functions for deleting array duplicate strings and array values, which roughly means dividing strings into arrays or splitting and comparing them one by one and then removing duplicate strings.
Method 1

Public static string [] getstring (string [] values)
...{
List <string> list = new list <string> ();
For (int I = 0; I <values. length; I ++) // traverses array members
...{
If (list. indexof (values [I]. tolower () =-1)
// Perform a new array query for each member. If no query is equal, the query is added to the new array.
List. add (values [I]);
}
Return list. toarray ();
}

Method 2

1. string str = "22,333, 333,4,"; // string to be split by www. bKjia. c0m
2. arraylist al = new arraylist ();
3. string [] arr = str. split (','); // character array after splitting
4.
5. for (int I = 0; I <arr. length; I ++)
6 .{
7. if (al. contains (arr [I]) = false) // determine whether the string to be split already exists in this arraylist
8 .{
9. al. add (arr [I]); // add it to arraylist if it does not exist.
10 .}
11. else
12 .{
13. al. remove (arr [I]); // If yes, it will be deleted from the arraylist.
14 .}
15 .}
16. response. write (string. join (",", (string []) al. toarray (typeof (string ))));//

// Method 3
*/

Public static string [] removedup (string [] mydata)
...{
If (mydata. length> 0)
...{
Array. sort (mydata); // mb. bKjia. c0m first sorts the array
Int size = 1; // defines the length of the array after the repeated items are deleted.
For (int I = 1; I
 
Return mydata;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.