 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Substring in C#
Substring is used to get the sub-parts of a string in C#. We have the substring() method for this purpose. Use the substring() method in C# to check each and every substring for unique characters. Loop it until the length of the string.
If anyone the substring matches another, then it would mean that the string does not have unique characters.
You can try to run the following code to determine if a string has all unique characters. The example shows the usage of Substring() method −
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();    } }Advertisements
 