-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathHelper.cs
69 lines (61 loc) · 2.02 KB
/
Helper.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace FileCounter
{
/// <summary>
/// 静态辅助方法
/// </summary>
static class Helper
{
/// <summary>获取程序版本号</summary>
public static string GetVersion()
{
var v = Assembly.GetExecutingAssembly().GetName().Version;
return string.Format("{0}.{1}.{2}", v.Major, v.Minor, v.Revision);
}
/// <summary>文本拆分成数组</summary>
public static string[] ToArray(this string text)
{
return text.Replace(" ", "")
.Replace("\r", "")
.Replace("\n", "")
.Replace("\t", "")
.Split('|', ',', ';');
}
/// <summary>文本为空</summary>
public static bool IsEmpty(this string text)
{
return string.IsNullOrEmpty(text);
}
/// <summary>转化为布尔</summary>
public static bool ToBool(this string text)
{
if (!text.IsEmpty() && text.ToLower() == "true")
return true;
return false;
}
/// <summary>文本是注释行</summary>
public static bool IsCommentLine(this string text)
{
if (text.IsEmpty())
return false;
text = text.TrimStart();
return (text.StartsWith("//") || text.StartsWith("#"));
}
/// <summary>转化为逗号分隔的字符串</summary>
public static string ToSeparatedString(this IEnumerable source, char seperator = ',')
{
if (source == null)
return "";
string txt = "";
foreach (var item in source)
txt += item.ToString() + seperator;
return txt.TrimEnd(seperator);
}
}
}