डुप्लिकेट शब्दों के साथ एक स्ट्रिंग सेट करें।
string str = "One Two Three One";
ऊपर, आप देख सकते हैं कि "एक" शब्द दो बार आता है।
डुप्लिकेट शब्दों को हटाने के लिए, आप निम्नलिखित कोड को C# में चलाने का प्रयास कर सकते हैं -
उदाहरण
using System;
using System.Linq;
public class Program {
public static void Main() {
string str = "One Two Three One";
string[] arr = str.Split(' ');
Console.WriteLine(str);
var a =
from k in arr
orderby k
select k;
Console.WriteLine("After removing duplicate words...");
foreach(string res in a.Distinct()) {
Console.Write(" " + res.ToLower());
}
Console.ReadLine();
}
} आउटपुट
One Two Three One After removing duplicate words... one three two