Saturday, 2 December 2017

C# Program to Display the Abbreviation of a Text


Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class abbreviation
{
    string str;
    public void readdata()
    {
        Console.WriteLine("Enter a String :");
        str=Console.In.ReadLine();
    }
    public void abbre()
    {
        char[] c, result;
        int j = 0;
        c = new char[str.Length];
        result = new char[str.Length];
        c = str.ToCharArray();
        result[j++] = (char)((int)c[0] ^ 32);
        result[j++] = '.';
        for (int i = 0; i < str.Length - 1; i++)
        {
            if (c[i] == ' ' || c[i] == '\t' || c[i] == '\n')
            {
                int k = (int)c[i + 1] ^ 32;
                result[j++] = (char)k;
                result[j++] = '.';
            }
        }
            Console.Write("The Abbreviation for {0} is ", str);
            Console.WriteLine(result);
            Console.ReadLine();

    }
        public static void Main()
        {
            abbreviation obj=new abbreviation();
            obj.readdata();
            obj.abbre();
        }
}


Output:

Enter a String : 
meenakshi sundarajan engineering college
The Abbreviation for meenakshi sundarajan  engineering college is M.S.E.C.


More C# Programs:



















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...