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;
}