0% found this document useful (0 votes)
15 views6 pages

String Function

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

String Function

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

...SER\source\repos\ConsoleApp3\Using_Strings\Program.

cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Security.Cryptography;
5 using System.Security.Cryptography.X509Certificates;
6 using System.Text;
7 using System.Threading.Tasks;
8 using static System.Runtime.InteropServices.JavaScript.JSType;
9
10 namespace Using_Strings
11 {
12 public class StringFunc
13 {
14 public int GetLength(string str)
15 {
16 int count = 0;
17
18 foreach (char c in str)
19 {
20 count++;
21 }
22
23
24 return count;
25 }
26
27 public void IndividualCharacters(string str)
28 {
29
30
31 foreach (char c in str)
32 {
33
34 Console.Write(c + " ");
35 }
36
37
38 }
39
40 public void ICReverse(string str)
41 {
42
43 for (int i = str.Length - 1; i >= 0; i--)
44 {
45 Console.Write(str[i] + " ");
46 }
47
48
49 }
...SER\source\repos\ConsoleApp3\Using_Strings\Program.cs 2
50
51 public void CompareString(string a, string b)
52 {
53 if (a == b)
54 {
55 Console.WriteLine("True");
56 }
57 else
58 {
59 Console.WriteLine("False");
60 }
61 }
62
63 public void Totalcount(string d)
64 {
65
66 int alphabetCount = 0;
67 int digitCount = 0;
68 int specialCharCount = 0;
69
70 foreach (char c in d)
71 {
72 if (char.IsLetter(c))
73 {
74 alphabetCount++;
75 }
76 else if (char.IsDigit(c))
77 {
78 digitCount++;
79 }
80 else if (!char.IsWhiteSpace(c))
81 {
82 specialCharCount++;
83 }
84 }
85
86 Console.WriteLine("Number of Alphabets : " +
alphabetCount);
87 Console.WriteLine("Number of Digits : " +
digitCount);
88 Console.WriteLine("Number of Special Characters : " +
specialCharCount);
89 }
90
91 public void VowelsCount(string a)
92 {
93
94 string _a = a.ToLower();
95 int vowelsCount = 0;
...SER\source\repos\ConsoleApp3\Using_Strings\Program.cs 3
96
97
98 foreach(char c in _a)
99 {
100 if("aeiou".Contains(c))
101 {
102 vowelsCount++;
103 }
104 }
105
106
107 Console.WriteLine("Number of Vowles : " +
vowelsCount);
108 }
109
110
111 public void MaxiChar(string a1)
112 {
113
114 int[] charCounts = new int[26];
115
116
117 foreach (char item in a1.ToLower())
118 {
119 if (item >= 'a' && item <= 'z')
120 {
121 charCounts[item - 'a']++;
122 }
123 }
124
125
126 int maxCount = 0;
127 char maxChar = ' ';
128
129 for (int i = 0; i < charCounts.Length; i++)
130 {
131 if (charCounts[i] > maxCount)
132 {
133 maxCount = charCounts[i];
134 maxChar = (char)(i + 'a');
135 }
136 }
137
138
139 Console.WriteLine($"The most used character is '{maxChar}'
with {maxCount} occurrences.");
140 }
141
142 public void SortMethod(string x)
...SER\source\repos\ConsoleApp3\Using_Strings\Program.cs 4
143 {
144
145
146 char[] words = x.ToCharArray();
147
148
149 Array.Sort(words);
150
151 // Display the sorted array
152 Console.WriteLine("Sorted words in ascending order:");
153 foreach (char word in words)
154 {
155 Console.Write(word + " ");
156 }
157 }
158 }
159
160
161
162 class Program
163 {
164 static void Main()
165 {
166
167 string a = "uniq technologies";
168
169 string b = "This is first string";
170 string c = "This is first string";
171
172 string d = "Welcome 2 Uniq.technologies";
173
174
175
176
177
178 StringFunc func = new StringFunc();
179
180
181
182
183 //Find Length
184
185 Console.Write("Get Length Function : ");
186 Console.WriteLine(func.GetLength(a));
187
188 //Character vise
189 Console.WriteLine("\n");
190 Console.Write("Character vise : ");
191 func.IndividualCharacters(a);
...SER\source\repos\ConsoleApp3\Using_Strings\Program.cs 5
192
193 //reverse Print
194 Console.WriteLine("\n");
195 Console.Write("Reverse Process Print : ");
196 func.ICReverse(a);
197
198
199 //Compare Process
200 Console.WriteLine("\n");
201 Console.Write("Compare 2 strings : ");
202 func.CompareString(b, c);
203
204 //Total Count
205 Console.WriteLine("\n");
206 Console.WriteLine("Total string count : ");
207 func.Totalcount(d);
208
209
210
211 //Total Vowles count
212 Console.WriteLine("\n");
213 Console.Write("Vowels count : ");
214 func.VowelsCount(a);
215
216
217 //Maximum Character Count
218 Console.WriteLine("\n");
219 Console.WriteLine("Maximum Character count : ");
220 func.MaxiChar(a);
221
222
223 //Sort String
224 Console.WriteLine("\n");
225 Console.WriteLine("Asscending Order : ");
226 func.SortMethod(a);
227
228
229
230 /*string a = "One MAN Army";
231 string b = "One MAN ";
232 int b1 = a.Length;
233 int c = a.IndexOf("O");
234
235 Console.WriteLine(a.Remove(0, 3));
236
237 string n = a.Substring(0, 3);
238 Console.WriteLine(n);
239
240
...SER\source\repos\ConsoleApp3\Using_Strings\Program.cs 6
241 a.Replace("e", "eday");
242 string d = (string)a.Clone();
243 string e = String.Copy(a);
244
245 string f = String.Intern(a);
246 bool g = a.Equals(b);
247 bool h = a.Contains("O");
248 string i = a.Trim();
249 string j = a.TrimEnd();
250 string k = a.TrimStart();
251 string l = a.ToLower();
252 string m = a.ToUpper();
253
254 string[] o = a.Split();
255 string p = String.Join(" ", o);
256 char[] q = a.ToCharArray();
257 string r = String.Join("", q);
258 string s = String.Concat(p, r);
259 Console.WriteLine(String.Compare(s, r));
260
261 Console.WriteLine("Hi" + n + "hi");
262 Console.WriteLine(s);
263 Console.WriteLine(a.Replace("e", "eday"));
264
265 foreach (char x in q)
266 {
267 Console.WriteLine(x);
268 Console.WriteLine("finish");
269 }*/
270 }
271 }
272 }
273

You might also like