
- 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 determine if a string has all unique characters
Use the substring() method in C# to check each and every substring for unique characters. Loop it until the length of the string.
If any one the substring matches another, then it would mean that the string do not have unique characters.
You can try to run the following code to determine if a string has all unique characters.
Example
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class Demo { public bool CheckUnique(string str) { string one = ""; string two = ""; for (int i = 0; i < str.Length; i++) { one = str.Substring(i, 1); for (int j = 0; j < str.Length; j++) { two = str.Substring(j, 1); if ((one == two) && (i != j)) return false; } } return true; } static void Main(string[] args) { Demo d = new Demo(); bool b = d.CheckUnique("amit"); Console.WriteLine(b); Console.ReadKey(); } }
Output
True
- Related Articles
- How to determine if the string has all unique characters using C#?
- Python program to check if a string contains all unique characters
- Checking if a string contains all unique characters using JavaScript
- Count Unique Characters of All Substrings of a Given String in C++
- Java Program to Print all unique words of a String
- Java program to find all duplicate characters in a string
- Python program to find all duplicate characters in a string
- Check if a string has all characters with same frequency with one variation allowed in Python
- Program to find length of concatenated string of unique characters in Python?
- C++ Program to Remove all Characters in a String Except Alphabets
- How to find unique characters of a string in JavaScript?
- Filtering string to contain unique characters in JavaScript
- Python program to check if a string contains any unique character
- Program to find minimum required chances to form a string with K unique characters in Python
- Mapping unique characters of string to an array - JavaScript

Advertisements