C# में Substring() Method का उपयोग करके प्रत्येक Substring को Unique Characters के लिए Check करें। इसे String की Length तक Loop करें।
यदि कोई Substring दूसरी से Match करता है, तो इसका मतलब होगा कि String में Unique Characters नहीं हैं।
String में सभी Unique Characters हैं या नहीं Determine करने के लिए निम्न Code Run करें।
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