How to determine if the string has all unique characters using C#?

CsharpProgrammingServer Side Programming

To determine if a string has unique characters or not, firstly check a word in the string with the next word −

for (int j = i + 1; j < val.Length; j++) {
   if (val[i] == val[j])
}

If you find a match, that would mean the string do not have unique characters.

If you are unable to find a match, then the string has all unique characters.

In case of a match, return false i.e. unique characters not found −

for (int j = i + 1; j < val.Length; j++) {
   if (val[i] == val[j])
   return false;
}
raja
Published on 10-Aug-2018 11:04:30
Advertisements