-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
45 lines (36 loc) · 1.09 KB
/
Program.cs
File metadata and controls
45 lines (36 loc) · 1.09 KB
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
using System.Diagnostics;
string CreateString()
{
string sample = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
Random rnd = new Random();
int length = 1000000000;
char[] originalArr = new char[length];
originalArr[0] = sample[rnd.Next(sample.Length)];
for (int i = 1; i < length; i++)
{
originalArr[i] = rnd.Next(2) == 1 ? ' ' : sample[rnd.Next(sample.Length)];
}
return String.Join(String.Empty, originalArr);
}
void TrimRight(string input)
{
int count = 0;
for (int i = input.Length - 1; input[i].Equals(' ') && i >= 0; i--)
count++;
char[] charArr = new char[input.Length - count];
for (int i = 0; i < charArr.Length; i++)
{
charArr[i] = input[i];
}
string output = String.Join(String.Empty, charArr);
// Console.Write(output);
}
string txt = CreateString();
// Console.Write(txt);
// Console.WriteLine("|");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
TrimRight(txt);
// Console.WriteLine("|");
stopwatch.Stop();
Console.WriteLine(stopwatch.ElapsedMilliseconds + " ms.");