-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensions.cs
60 lines (48 loc) · 1.2 KB
/
Extensions.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Linq;
namespace DotGLFW.Generator;
public static partial class Extensions
{
public static string Remove(this string str, string toRemove)
{
return str.Replace(toRemove, "");
}
public static string FixSpaces(this string str)
{
if (!str.Contains(" "))
{
return str;
}
if (!str.Split(" ").Where(x => x != "").Any())
{
return str;
}
return str.Split(" ").Where(x => x != "").Aggregate((x, y) => $"{x} {y}");
}
public static string FixNewlines(this string str)
{
if (!str.Contains("\n"))
{
return str;
}
if (!str.Split("\n").Where(x => x != "").Any())
{
return str;
}
return str.Split("\n").Where(x => x != "").Aggregate((x, y) => $"{x} {y}");
}
public static int Count(this string str, char c)
{
return str.Count(x => x == c);
}
public static string Repeat(this string str, int count)
{
return string.Concat(Enumerable.Repeat(str, count));
}
public static string Capitalize(this string str)
{
if (str.Length <= 1)
return str.ToUpper();
return char.ToUpper(str[0]) + str.Substring(1);
}
}