Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Check a given string is an isograms or not

C# Sharp String: Exercise-51 with Solution

Write a C# Sharp program to check whether a given string is an "isograms" or not. Return True or False.

From Wikipedia,
A heterogram (from hetero-, meaning 'different', + -gram, meaning 'written') is a word, phrase, or sentence in which no letter of the alphabet occurs more than once. The terms isogram and nonpattern word have also been used to mean the same thing.

Sample Solution:-

C# Sharp Code:

using System;
using System.Linq;
using System.Collections.Generic;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            string str1 = "Python";
            Console.WriteLine("Original string: "+ str1);
            Console.WriteLine("Check the said string is an 'isograms' or not! " + test(str1));
            str1 = "JavaScript";
            Console.WriteLine("\nOriginal string: " + str1);
            Console.WriteLine("Check the said string is an 'isograms' or not! " + test(str1));
            str1 = "PHP";
            Console.WriteLine("\nOriginal string: " + str1);
            Console.WriteLine("Check the said string is an 'isograms' or not! " + test(str1));
            str1 = "C#";
            Console.WriteLine("\nOriginal string: " + str1);
            Console.WriteLine("Check the said string is an 'isograms' or not! " + test(str1));
        }
        public static bool test(string str1)
        {
            int str_len = str1.Length;
            return str1.ToLower().Distinct().Count() == str_len;
        }
    }
}

Sample Output:

Original string: Python
Check the said string is an 'isograms' or not! True

Original string: JavaScript
Check the said string is an 'isograms' or not! False

Original string: PHP
Check the said string is an 'isograms' or not! False

Original string: C#
Check the said string is an 'isograms' or not! True

Flowchart :

Flowchart: C# Sharp Exercises - Check a given string is an isograms or not.

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to find the maximum and minimum number from a given string of numbers separated by single space.
Next: Write a C# Sharp program to convert the first character of each word of a given string to uppercase.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.