| | | 1 | | namespace Utility.Common; |
| | | 2 | | |
| | | 3 | | public static class StringExtensions |
| | | 4 | | { |
| | | 5 | | // https://stackoverflow.com/a/4405876/2895831 |
| | | 6 | | public static string FirstCharToUpper(this string input) => |
| | | 7 | | input switch |
| | | 8 | | { |
| | | 9 | | null => throw new ArgumentNullException(nameof(input)), |
| | | 10 | | "" => throw new ArgumentException($"{nameof(input)} cannot be empty", nameof(input)), |
| | | 11 | | _ => string.Concat(input[0].ToString().ToUpper(), input.AsSpan(1)) |
| | | 12 | | }; |
| | | 13 | | } |
| | | 14 | | |
| | | 15 | | // https://stackoverflow.com/a/41748138/2895831 |
| | | 16 | | public static class InvertStringExtension |
| | | 17 | | { |
| | | 18 | | public static string Invert(this string s) |
| | 0 | 19 | | { |
| | 0 | 20 | | char[] chars = s.ToCharArray(); |
| | 0 | 21 | | for (int i = 0; i < chars.Length; i++) |
| | 0 | 22 | | chars[i] = chars[i].Invert(); |
| | | 23 | | |
| | 0 | 24 | | return new string(chars); |
| | 0 | 25 | | } |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | // https://stackoverflow.com/a/41748138/2895831 |
| | | 29 | | public static class InvertCharExtension |
| | | 30 | | { |
| | | 31 | | public static char Invert(this char c) |
| | | 32 | | { |
| | | 33 | | if (!char.IsLetter(c)) |
| | | 34 | | return c; |
| | | 35 | | |
| | | 36 | | return char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c); |
| | | 37 | | } |
| | | 38 | | } |