প্রথমে স্ট্রিং সেট করুন:
string str = "Website";
Console.WriteLine("String: " + str);
স্ট্রিংয়ের প্রতিটি ক্যারেক্টার চেক করে সেই ক্যারেক্টারের অকারেন্স গণনা করুন:
for (int j = 0; j < str.Length; j++) {
if (str[0] == str[j]) {
cal++;
}
}
সম্পূর্ণ উদাহরণ
using System;
public class Demo {
public static void Main() {
string str = "Website";
Console.WriteLine("String: " + str);
while (str.Length > 0) {
Console.Write(str[0] + " = ");
int cal = 0;
for (int j = 0; j < str.Length; j++) {
if (str[0] == str[j]) {
cal++;
}
}
Console.WriteLine(cal);
str = str.Replace(str[0].ToString(), string.Empty);
}
Console.ReadLine();
}
}
আউটপুট
String: Website W = 1 e = 2 b = 1 s = 1 i = 1 t = 1
ব্যাখ্যা: প্রতিবার প্রথম ক্যারেক্টারের কাউন্ট নিয়ে সেটি স্ট্রিংয়ের থেকে রিমুভ করা হয়।