These days to do a project, just want to use to remove the string repetition of the characters, began to do not know how to write this algorithm, but through the Internet to find some relevant information, finally there is a general idea, so set thinking broad discussion bar, summed up the following two kinds:
This is passed in an array:
public static string[] Removedup (string[] myData)
{
if (Mydata.length > 0)
{
Array.Sort (MyData)//using array sorting, personal feeling can improve a little more efficiency when the elements of the array are many!
int size = 1; At least 1
for (int i = 1; i < mydata.length; i++)
if (Mydata[i]!= mydata[i-1])
size++;
string[] Mytempdata = new String[size];
int j = 0;
Mytempdata[j++] = mydata[0];
for (int i = 1; i < mydata.length; i++)
if (Mydata[i]!= mydata[i-1])
Mytempdata[j++] = Mydata[i];
return mytempdata;
}
return myData;
}
This is passed in a string that is no different than the one above.
public static string[] Removedupstring (String myString)
{
string[] MyData = Mystring.split (' # ');
if (Mydata.length > 0)
{
Array.Sort (MyData);
int size = 1; At least 1
for (int i = 1; i < mydata.length; i++)
if (Mydata[i]!= mydata[i-1])
size++;
string[] Mytempdata = new String[size];
int j = 0;
Mytempdata[j++] = mydata[0];
for (int i = 1; i < mydata.length; i++)
if (Mydata[i]!= mydata[i-1])
Mytempdata[j++] = Mydata[i];
return mytempdata;
}
return myData;
}
Write a little bit of algorithm, I think my ability will improve faster! This is what I learned from my colleagues!