-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKs.cs
54 lines (50 loc) · 1.38 KB
/
Ks.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace CopasiApi
{
class Ks
{
private string SOURCE_FOLDER = "plaur";
private string SOURCE_FILE = "par-est.txt";
private string TARGET_FILE = "ks.txt";
public Ks()
{
var file = SOURCE_FOLDER + "/" + SOURCE_FILE;
var text = File.ReadAllText(file);
var names = GetNames(text);
var values = GetValues(text);
var builder = new StringBuilder();
var index = 0;
names.ForEach((name) =>
{
builder.AppendLine(name + "\t" + values[index]);
index++;
});
File.WriteAllText(SOURCE_FOLDER + "/" + TARGET_FILE, builder.ToString().Trim());
}
private List<string> GetNames(string text)
{
var regex = new Regex("Values\\[(.+)\\]");
var matches = regex.Matches(text);
var names = matches.ToList().Select((match) =>
{
var groups = match.Groups;
var name = groups[1].Value;
return name;
});
return names.ToList();
}
private List<string> GetValues(string text)
{
var regex = new Regex("\\((.+)\\)");
var matches = regex.Matches(text);
var lastMatch = matches.ToList().Last();
var values = lastMatch.Groups[1].Value.Trim();
return values.Split("\t").ToList();
}
}
}