-
Notifications
You must be signed in to change notification settings - Fork 18
/
GIVEN A STRING 555-666-1234 DISPLAY AS 55-56-661-234.cs
75 lines (71 loc) · 2.05 KB
/
GIVEN A STRING 555-666-1234 DISPLAY AS 55-56-661-234.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication132
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the string:");
string ph = Console.ReadLine();
char[] p = ph.ToCharArray();
string sp = "-";
int count = 0;
string outpt = string.Empty;
string phneno = string.Empty;
int i, L,L1,j;
L = p.Length;
for (i = 0; i < L; i++)
{
if ((int)p[i]>=48&&(int)p[i]<=57)
{
phneno = phneno + p[i];
}
}
Console.WriteLine("\n");
char[] p1 = phneno.ToCharArray();
L1 = p1.Length;
for (j = 0; j < L1; j++)
{
if (count == 2||count==3)
{
outpt = outpt + p1[j];
if (count == 3)
{
outpt = outpt + sp;
}
count++;
}
else if (count == 4 || count == 5 || count == 6)
{
outpt = outpt + p1[j] ;
if (count == 6)
{
outpt = outpt + sp;
}
count++;
}
else if (count == 7 || count == 8 || count == 9)
{
outpt = outpt + p1[j];
count++;
}
else if (count == 0 || count == 1)
{
outpt = outpt+p1[j] ;
if (count == 1)
{
outpt = outpt + sp;
}
count++;
}
}
Console.WriteLine(outpt);
Console.WriteLine("\n");
Console.ReadLine();
}
}
}