string s = "Hello World"; string tempString = ""; foreach (char c in s) { //Append the character, If character is already in the string append the "" value else append the character tempString += tempString.Contains(c.ToString()) ? "" : c.ToString(); } MessageBox.Show(tempString); //[OutPut: Helo Wrld]
using System.Collections.Generics; string str = "00121234455"; string temp = string.Empty; List<string> list = new List<string>(); for (int i = 1; i <= str.length; i++) { temp = str.SubString(i-1, i); // get all the characters one by one if (!list.Contains(temp)) { list.Add(temp); } } string distinctString = list.ToString();
Thanks, T.Saravanan
foreach(char c in strVariable) { //Do Work here... }
Login to post response