sale

sale

  • NA
  • 15
  • 563

how to remove duplicate from a string?

Nov 6 2018 1:56 PM

Hi,

I am new to c-sharp programming and need your help.

I have written the following code to remove duplicate from the word. But don’t get the correct result.

Would you please check, what is going wrong and how the correct code look like?

for exemple if the word is "google"
the result should be gole 

Thanks in advance

private void Form1_Load(object sender, EventArgs e)

{

string word = "google";

int len = word.Length;

string result = "";

for (int i = 0; i <len; i++)

{

for (int j = 0; j < len; j++)

{

if (!( word[i] == result[j]))

{

result = result + word[i];

MessageBox.Show("Result" + result);

}

}

}

}


Answers (7)