This is a C# Program to display the abbreviation of a text.
This C# Program Displays the Abbreviation of a Text.
Here the string is obtained from the user and the abbreviation of the corresponding string is found and displayed.
Here is source code of the C# Program to Display the Abbreviation of a Text. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Display the Abbreviation of a Text */ 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(); } }
In this C# program, we are creating an object ‘obj’ variable to the abbreviation class. In readdata() function we are reading a string using ‘str’ variable. In abbre() procedure we are printing the abbreviation of a text.
Compute the length of the string present in the ‘str’ variable. For loop is used to print the abbreviation of the text. Initialize the value of ‘i’ variable as 0 and check the condition that the value of ‘i’ variable is less than or equal to the length of the string entered by the user.
If the condition is true then execute the iteration of the loop. If condition statement is used to check the value of c[] variable is equal to empty space or newline using Logical OR Operator, if the condition is true then execute the statement. Print the string obtained from the user and the abbreviation of the corresponding string.
Enter a String : meenakshi sundarajan engineering college The Abbreviation for meenakshi sundarajan engineering college is M.S.E.C.
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for C# Internship
- Buy Computer Science Books
- Buy C# Books
- Apply for Computer Science Internship
- Buy MCA Books