schangxiang@126.com
2024-04-25 4d14b84903bf0277c5e8b9b3138c5e1d981e95db
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
#nullable enable
 
using System.Text;
using System.Text.RegularExpressions;
 
namespace Admin.NET.Core
{
    public static class StringUtil
    {
        /// <summary>
        /// 获取下划线表达式
        /// </summary>
        /// <param name="camel"></param>
        /// <returns></returns>
        public static string ToUnderLine(this string camel)
        {
            return Regex.Replace(camel, "([A-Z])", "_$1").ToLower().TrimStart('_');           
        }
 
 
        /// <summary>
        /// 获取下划线表达式
        /// </summary>
        /// <param name="camel"></param>
        /// <returns></returns>
        public static string ToUnderLine(this string camel, char trimChar)
        {
            return Regex.Replace(camel, "([A-Z])", trimChar + "$1").ToLower().TrimStart(trimChar);
        }
 
 
        /// <summary>
        /// 获取驼峰表达式
        /// </summary>
        /// <param name="camel"></param>
        /// <returns></returns>
        public static string ToCamel(this string str)
        {
            if(string.IsNullOrEmpty(str)) return "";
            return str[..1].ToLower() + str[1..];
        }
 
 
        /// <summary>
        /// 将类型进行转换
        /// </summary>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public static string ParseTrueType(string dataType) 
        {
            if(!dataType.StartsWith("System.Nullable")) return dataType;
 
            return new Regex(@"(?i)(?<=\[)(.*)(?=\])").Match(dataType).Value;    
        }
 
        /// <summary>
        /// 将类型进行转换
        /// </summary>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public static string ParseTrueType2(string dataType)
        {
            if (!dataType.StartsWith("System.Nullable")) return dataType;
 
            var str = new Regex(@"(?i)(?<=\[\[)(.*)(?=\]\])").Match(dataType).Value;
 
            var args = str.Split(',');
 
            return args.Length > 0 ? args[0] : "";
        }
 
        /// <summary>
        /// 分割字符
        /// </summary>
        /// <returns></returns>
        public static string SplitChar() 
        {
            return new ASCIIEncoding().GetString(new byte[] { 3 });
        }
 
 
    }
}