Parsar - Using String Methods in C#

parser is a compiler / interpreter component that breaks data into smaller elements for easy translation into another language. A parser takes input in the form of a sequence of tokens or program instructions and usually builds a data structure in the form of a parse tree or an abstract syntax tree.


Parsar - Using String Methods in C#


C Sharp is usually known as C#. This Language is basically the Programming Language which is mainly used for object orientation. this language was developed by Microsoft. i personally feel that many people face problem while writing such codes for particular program.

Here is a programing C Sharp (c#), How to Create a Parsar of String Methods in which User give you an input and edit it by using your Parsar.

CODE:


class Program    {        static void Main(string[] args)
        {             Console.WriteLine("\t\t\t\tWelcome To WAKFA Story Competetion");
            Console.WriteLine("\nOrganizers are:\n\t\tSyed Ahsan Raza");
            Console.WriteLine("\t\tFaisal Mukhtar");
            Console.WriteLine("\t\tAqsa Ghaffar");
            Console.WriteLine("\t\tKhadija Amjad");
            Console.WriteLine("\t\tWadiya Ali\n");
            Console.WriteLine("\n(NOTE) Story with the best moral lesson will be considered as the best one.\n\t\t\tStory should be 50-100 words.\n\t\t\t\tGood luck !\n");
            Console.WriteLine("Please enter your story.");
            string Story = Console.ReadLine();
            Console.WriteLine("\n----------------------------\n");
            Console.WriteLine("Here is your story:\n\t" + "'' " + Story + " ''");
            while (true)
            {                Console.WriteLine("\n\t\t\t\tDo you want to make any changes?(Y/N)");
                char a = Convert.ToChar(Console.ReadLine());
                if (a == 'y' || a == 'Y')
                {                    Console.WriteLine("Please select the operation:\n 1.Contains \t\t\t 2.Lowercase");
                    Console.WriteLine(" 3.Uppercase \t\t\t 4.Insert ");
                    Console.WriteLine(" 5.Length \t\t\t 6.Remove ");
                    Console.WriteLine(" 7.Replace \t\t\t 8.Split ");
                    Console.WriteLine(" 9.Trim \t\t\t 10.Index");
                    Console.WriteLine(" 11.Substring \t\t\t 12.Endswith");
                    int n = Convert.ToInt32(Console.ReadLine());
                    switch (n)
                    {                        case 1:
                            Console.WriteLine("CONTAIN \n Enter the word you want to find:");
                            string b = Console.ReadLine();
                            Contain(Story, b);                            break;
                        case 2:
                            Lowercase(Story);                            break;
                        case 3:
                            Console.WriteLine("UPPERCASE \n Enter the word you want to change to uppercase:");
                            string d = Console.ReadLine();
                            Uppercase(Story, d);                            break;
                        case 4:
                            Console.WriteLine("Enter the word before which you want to insert something");
                            string Valuee = Console.ReadLine();
                            Console.WriteLine("Now enter the word/words you want to insert");
                            string change = Console.ReadLine();
                            Insert(Story, Valuee,change);                            break;
                        case 5:
                         
                            Length(Story);                            break;
                        case 6:
                            Console.WriteLine("REMOVE \n Enter the word you want to remove:");
                            string g = Console.ReadLine();
                            Remove(Story, g);                            break;
                        case 7:
                            Console.WriteLine("REPLACE \n Find:");
                            string h = Console.ReadLine();
                            Console.WriteLine("Replace with:");
                            string i = Console.ReadLine();
                            Replace(Story, h, i);                            break;
                        case 8:
                            Program.Split(Story);
                            break;
                        case 9:
                            Trim(Story);                            break;
                        case 10:
                            Console.WriteLine("INDEX\nEnter the word");
                            string k = Console.ReadLine();
                            Console.WriteLine("Index of the word is");
                            Console.WriteLine( Index (Story,k));
                            break;
                        case 11:
                            Program.substring(Story);
                            break;
                        case 12:
                            Program.endswith(Story);
                            break;
                        default:
                            Console.WriteLine("Invalid Selection..!");
                            break;
                     }                 
                }                else                {                    break;
                }            }        }        public static void Contain(string a, string b)
        {            Console.WriteLine(a.Contains(b));
        }        public static void  Lowercase(string a)
        {            Console.WriteLine("LOWERCASE \n Enter the word you want to change to lowercase:");
            string c = Console.ReadLine();
            Console.WriteLine(a.Replace(c,c.ToLower()));
        }        public static void Uppercase(string a, string b)
        {            Console.WriteLine(a.Replace(b, b.ToUpper()));
        }        public static void Insert(string a, string b,string c)
        {         
            Console.WriteLine(a.Insert(Index(a,b)," "+c));
        }        public static void Length(string a)
        {            int Length = a.Length;
            Console.WriteLine("Length of your string is " + Length);
        }        public static void Remove(string a, string b)
        {            Console.WriteLine(a.Remove(Index(a, b),b.Length));
         
        }        public static void Replace(string a, string b, string c)
        {            Console.WriteLine(a.Replace(b, c));
        }        public static void Split(string a)
        {            Console.WriteLine("SPLIT \nEnter a Character From where do you want to split your document?");
            char b = Convert.ToChar(Console.ReadLine());
            string[] array = a.Split(b);
            foreach(string word in array)
            {                Console.WriteLine(word);
            }        }        public static void Trim(string a)
        {            Console.WriteLine("Your story is successfully trimmed.");
            Console.WriteLine("-----------------------------------");
            Console.WriteLine(a.Trim());
        }        public static int Index(string a,string b)
        {            int Position =a.IndexOf(b);
            return Position;
        }        public static void substring(string sedo)
        {            Console.WriteLine("Enter the Starting string value: ");
            int first = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter the lenght of string value: ");
            int final = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();
            Console.WriteLine(sedo.Substring(first, final));
        }        public static void endswith(string redo)
        {            Console.WriteLine("Enter the Word for Endswith Method: ");
            string nope = Console.ReadLine();
            Console.WriteLine(redo.EndsWith(nope));
        }        }     }

Execute this program And Show us the Output of Your Program.

Faisal Mukhtar

Assalam u Alaikum. I am web Developer, Web Application Developer, Web Designer, Free Lancer, Intro and outro maker, Logo Designer. If you like my work, so kindly give your feedbacks and intouch with me through my Social Links. Thank You