-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAbbreviation.cs
41 lines (41 loc) · 1.07 KB
/
Abbreviation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 abbreviate()
{
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.abbreviate();
}
}