-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathStringExtensions.cs
41 lines (34 loc) · 1.01 KB
/
StringExtensions.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;
namespace Name
{
public static class StringExtensions
{
private const int ConsoleWidth = 120; // default console width
public static string CentreAlign(this string value)
{
int spaces = ConsoleWidth - value.Length;
int leftPadding = spaces / 2 + value.Length;
return value.PadLeft(leftPadding).PadRight(ConsoleWidth);
}
public static string Reverse(this string value)
{
if (value is null)
{
return null;
}
char[] characterArray = value.ToCharArray();
Array.Reverse(characterArray);
return new String(characterArray);
}
public static string Sort(this string value)
{
if (value is null)
{
return null;
}
char[] characters = value.ToCharArray();
Array.Sort(characters);
return new string(characters);
}
}
}