
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# program to remove all duplicates words from a given sentence
Set a string with duplicate words.
string str = "One Two Three One";
Above, you can see the word “One” comes twice.
To remove dulicate words, you can try to run the following code in C# −
Example
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(); } }
Output
One Two Three One After removing duplicate words... one three two
- Related Articles
- Java program to remove all duplicates words from a given sentence
- Python program to remove all duplicates word from a given sentence.
- Remove all duplicates from a given string in C#
- Remove all duplicates from a given string in Python
- Python program to remove Duplicates elements from a List?
- Java program to remove duplicates elements from a List
- Write a program in C++ to remove duplicates from a given array of prime numbers
- Golang Program To Remove Duplicates From An Array
- Python program to count words in a sentence
- Java Program to Remove Duplicates from an Array List
- Java program to remove all the white spaces from a given string
- Python program to sort Palindrome Words in a Sentence
- Reverse all the words of sentence JavaScript
- C++ program to convert all digits from the given range into words
- Count words in a sentence in Python program

Advertisements