Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Only unique chars into string?
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { var str = "This is not supposed to be a unique string."; //var str = "String"; // Method 1 var checkedChars = new List<char>(); var result = true; foreach(char c in str){ if(!checkedChars.Contains(c)) checkedChars.Add(c); else{ result = false; break; } } // Method 1 var result2 = str.Distinct().Count() == str.Length; // Throw results. Console.WriteLine("Is unique the list of chars in string? {0}, {1}", result, result2); } } }
run
|
edit
|
history
|
help
0
DecimalToStringConversion
0/1 Knapsack problem using Iterative Approach
DateTime
quadratics
MIXED CONTENT - string and numbers separation in a large string
Print 1 to 100 without using loop
Remove dublicates
D13
Dotnet Q-3
1.1 Basics: language constructs