- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 print duplicate characters in a String using C#?
Set maximum value for char.
static int maxCHARS = 256;
Now display the duplicate characters in the string.
String s = "Welcometomywebsite!"; int []cal = new int[maxCHARS]; calculate(s, cal); for (int i = 0; i < maxCHARS; i++) if(cal[i] > 1) { Console.WriteLine("Character "+(char)i); Console.WriteLine("Occurrence = " + cal[i] + " times"); }
Above, we have calculated the frequency of characters. The same is shown below in the complete example −
Example
using System; class Demo { static int maxCHARS = 256; static void calculate(String s, int[] cal) { for (int i = 0; i < s.Length; i++) cal[s[i]]++; } public static void Main() { String s = "Welcometomywebsite!"; int []cal = new int[maxCHARS]; calculate(s, cal); for (int i = 0; i < maxCHARS; i++) if(cal[i] > 1) { Console.WriteLine("Character "+(char)i); Console.WriteLine("Occurrence = " + cal[i] + " times"); } } }
- Related Articles
- Find All Duplicate Characters from a String using Python
- C# Program to remove duplicate characters from String
- Java Program to find duplicate characters in a String?
- How to print all the characters of a string using regular expression in Java?
- Python program to find all duplicate characters in a string
- Java program to find all duplicate characters in a string
- Java Program to Find the Duplicate Characters in a String
- Program to remove duplicate characters from a given string in Python
- Print all distinct characters of a string in order in C++
- Java program to delete duplicate characters from a given String
- JavaScript Remove non-duplicate characters from string
- How to print characters from a string starting from 3rd to 5th in Python?
- C program to print characters without using format specifiers
- Program to find string after removing consecutive duplicate characters in Python
- How to get last 2 characters from string in C# using Regex?

Advertisements