-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIniParser.cs
More file actions
38 lines (35 loc) · 1.26 KB
/
IniParser.cs
File metadata and controls
38 lines (35 loc) · 1.26 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
using System.IO;
using System.Linq;
namespace AstroModIntegrator
{
public static class IniParser
{
public static string FindLine(string rawData, string section, string key)
{
string currentSectionName = null;
using (StringReader reader = new StringReader(rawData))
{
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.Length < 3) continue;
if (line[0] == '[' && line[line.Length - 1] == ']')
{
currentSectionName = line.Substring(1, line.Length - 2);
}
else if (currentSectionName == section)
{
string[] fullLineData = line.Split('=');
if (fullLineData.Length >= 2)
{
string currentKey = fullLineData[0].Trim();
string currentValue = string.Join("=", fullLineData.Skip(1).ToArray()).Trim();
if (currentKey == key) return currentValue;
}
}
}
}
return null;
}
}
}