exp: Allahabad
Solution-
string cityName = "Allahabad";
string resultString = string.Empty;
var cityCharacters = (from c in cityName.ToLower()
orderby c
group c by c into temp
select new
{
data = temp,
count = temp.Count()
}).ToArray();
foreach (var item in cityCharacters)
{
if (item.count > 1)
{
resultString += " No of occurances for " + item.data.Key.ToString().ToUpper() + " - " + item.count + Environment.NewLine;
}
}
output: No of occurances for A - 4 No of occurances for L - 2
Solution-
string cityName = "Allahabad";
string resultString = string.Empty;
var cityCharacters = (from c in cityName.ToLower()
orderby c
group c by c into temp
select new
{
data = temp,
count = temp.Count()
}).ToArray();
foreach (var item in cityCharacters)
{
if (item.count > 1)
{
resultString += " No of occurances for " + item.data.Key.ToString().ToUpper() + " - " + item.count + Environment.NewLine;
}
}
output: No of occurances for A - 4 No of occurances for L - 2
No comments:
Post a Comment