Wednesday, November 14, 2018

C# program to make short name from fullname of user

 WAP  in C# to make shortname from fullname.

In this program of C# we are going to learn how to make short name from full name of user.
Here we some variables like fullname(to store fullname of user), shorname(to store short name of user), i(to make use of loop), lindex(to store the value of last index from where the space comes)
...................





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace stringprop
{
    class Program
    {
   
        static void Main(string[] args)
        {
            string fullname, shorname = " ";
            int i,lindex;
            Console.WriteLine("Enter your fullname:");
            fullname = Console.ReadLine().Trim();
            shorname = shorname + fullname[0] + "."; //Cut first letter from the name and '.' after that.
            lindex = fullname.LastIndexOf(' ');    //lindex hold the value of lastindex of function
            Console.WriteLine(lindex);
            for (i = 1; i < lindex; i++)
            {
                if (fullname[i] == ' ')
                {
                    shorname = (shorname + fullname[i + 1] + ".").ToUpper();
                }
            }
            shorname = shorname + fullname.Substring(lindex+1);
            Console.WriteLine("Your fullname is:"+fullname);
                Console.WriteLine("Your short name is:"+shorname);
            Console.ReadKey();
        }
    }
}

The Output will be:-


Some other programs are:-


No comments:

Post a Comment

IND vs AUS: Smith & Labuschagne Holds Fort As Fourth Test Ends Up In A Stalemate

  Beginning on 158 after Tea for the loss of two wickets for visiting Australian side with two stalwarts Steve Smith and   Marnus Labuschagn...