forked from Deadcows/MyBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyString.cs
100 lines (88 loc) · 2.08 KB
/
MyString.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System.Text.RegularExpressions;
namespace MyBox
{
public static class MyString
{
/// <summary>
/// "Camel case string" => "CamelCaseString"
/// </summary>
public static string ToCamelCase(this string camelCaseString)
{
return Regex.Replace(camelCaseString, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ").Trim();
}
/// <summary>
/// "CamelCaseString" => "Camel Case String"
/// </summary>
public static string SplitCamelCase(this string camelCaseString)
{
if (string.IsNullOrEmpty(camelCaseString)) return camelCaseString;
string camelCase = Regex.Replace(Regex.Replace(camelCaseString, @"(\P{Ll})(\P{Ll}\p{Ll})", "$1 $2"), @"(\p{Ll})(\P{Ll})", "$1 $2");
string firstLetter = camelCase.Substring(0, 1).ToUpper();
if (camelCaseString.Length > 1)
{
string rest = camelCase.Substring(1);
return firstLetter + rest;
}
return firstLetter;
}
/// <summary>
/// Surround string with "color" tag
/// </summary>
public static string Colored(this string message, Colors color)
{
return string.Format("<color={0}>{1}</color>", color, message);
}
/// <summary>
/// Surround string with "color" tag
/// </summary>
public static string Colored(this string message, string colorCode)
{
return string.Format("<color={0}>{1}</color>", colorCode, message);
}
/// <summary>
/// Surround string with "size" tag
/// </summary>
public static string Sized(this string message, int size)
{
return string.Format("<size={0}>{1}</size>", size, message);
}
/// <summary>
/// Surround string with "b" tag
/// </summary>
public static string Bold(this string message)
{
return string.Format("<b>{0}</b>", message);
}
/// <summary>
/// Surround string with "i" tag
/// </summary>
public static string Italics(this string message)
{
return string.Format("<i>{0}</i>", message);
}
}
public enum Colors
{
aqua,
black,
blue,
brown,
cyan,
darkblue,
fuchsia,
green,
grey,
lightblue,
lime,
magenta,
maroon,
navy,
olive,
purple,
red,
silver,
teal,
white,
yellow
}
}