-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToggle.cs
42 lines (36 loc) · 1.07 KB
/
Toggle.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1.StringEx
{
class Toggle
{
public void toggleCase(String sc)
{
char[] c = sc.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
if (c[i] >= 'a' && c[i] <= 'z')
{
c[i] = (char)(c[i] - 32);
}
else if (c[i] >= 'A' && c[i] <= 'Z')
{
c[i] = (char)(c[i] + 32);
}
}
String str = new String(c);
Console.WriteLine("Toggle case of each character of a string " + str);
Console.ReadLine();
}
static void Main(string[] args)
{
Console.WriteLine("Enter the String:");
String sc = Console.ReadLine();
Toggle o = new Toggle();
o.toggleCase(sc);
}
}
}