Repository navigation
Expand file tree
/
Copy pathPathHelper.cs
More file actions
78 lines (75 loc) · 2.85 KB
/
Copy pathPathHelper.cs
File metadata and controls
78 lines (75 loc) · 2.85 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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ArchiveData
{
//"D:\Program Files\7-Zip\7z.exe" a -t7z "D:\test\Data_TradingDay\20150326.7z" "D:\test\Data_TradingDay\20150326\*" -m0=PPMd -mx=9
//"D:\Program Files\7-Zip\7z.exe" a -t7z "D:\test\Data_TradingDay\20150326.7z" "D:\test\Data_TradingDay\20150326\*" -m0=PPMd -mx=9
public class PathHelper
{
public static bool SplitFileName(string fileName, out string exchange, out string product,
out string instrument, out string date)
{
exchange = string.Empty;
product = string.Empty;
instrument = string.Empty;
date = string.Empty;
// IF1503.CFFEX_20150430
// IF1503._20150430
// IO1506-C-2768._20150430
// SR503C1507.CZCE_20150430
// 600000.SSE_20150506
// SPC a1506&b1507._20150501
// IO1506-C-2768&IO1506-C-2768._20150501
Regex regex1 = new Regex(@"([A-za-z0-9\-& ]*)\.([A-za-z]*)_(\d{4,8})");
Match match1 = regex1.Match(fileName);
if (match1.Success)
{
instrument = match1.Groups[1].ToString();
exchange = match1.Groups[2].ToString();
date = match1.Groups[3].ToString();
if (instrument.IndexOf("&") > -1)
{
// SPC a1506&b1507
// IO1506-C-2768&IO1506-C-2768
char[] arr = instrument.ToCharArray();
for (int i = 0; i < arr.Length; i++)
{
if (!(arr[i] >= '0' && arr[i] <= '9' || arr[i]=='-'))
{
product += arr[i];
}
}
return true;
}
else
{
// IF1503
// SR503
// IO1503-C-2500
// SR503C500
// 600000
Regex regex2 = new Regex(@"([A-za-z]*)([0-9]+)([-CP]?)");
Match match2 = regex2.Match(instrument);
if (match2.Success)
{
if (string.IsNullOrEmpty(match2.Groups[3].ToString()))
{
product = match2.Groups[1].ToString();
}
else
{
product = match2.Groups[1].ToString() + match2.Groups[2].ToString();
}
return true;
}
}
}
return false;
}
}
}