forked from zhontai/Admin.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringExtensions.cs
More file actions
93 lines (83 loc) · 2.5 KB
/
StringExtensions.cs
File metadata and controls
93 lines (83 loc) · 2.5 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
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
using System;
using System.Linq;
using System.Text;
namespace Admin.Core
{
public static class StringExtensions
{
/// <summary>
/// 判断字符串是否为Null、空
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool IsNull(this string s)
{
return string.IsNullOrWhiteSpace(s);
}
/// <summary>
/// 判断字符串是否不为Null、空
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool NotNull(this string s)
{
return !string.IsNullOrWhiteSpace(s);
}
/// <summary>
/// 与字符串进行比较,忽略大小写
/// </summary>
/// <param name="s"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool EqualsIgnoreCase(this string s, string value)
{
return s.Equals(value, StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// 首字母转小写
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string FirstCharToLower(this string s)
{
if (string.IsNullOrEmpty(s))
return s;
string str = s.First().ToString().ToLower() + s.Substring(1);
return str;
}
/// <summary>
/// 首字母转大写
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string FirstCharToUpper(this string s)
{
if (string.IsNullOrEmpty(s))
return s;
string str = s.First().ToString().ToUpper() + s.Substring(1);
return str;
}
/// <summary>
/// 转为Base64,UTF-8格式
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string ToBase64(this string s)
{
return s.ToBase64(Encoding.UTF8);
}
/// <summary>
/// 转为Base64
/// </summary>
/// <param name="s"></param>
/// <param name="encoding">编码</param>
/// <returns></returns>
public static string ToBase64(this string s, Encoding encoding)
{
if (s.IsNull())
return string.Empty;
var bytes = encoding.GetBytes(s);
return bytes.ToBase64();
}
}
}