- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to determine if the string has all unique characters using C#?
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; }
Advertisements