-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckComplexVariable.cs
68 lines (64 loc) · 2.58 KB
/
checkComplexVariable.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace Script_Builder
{
public partial class checkComplexVariable : Form
{
string variableMarker;
public checkComplexVariable(string variableMarker)
{
this.variableMarker = variableMarker;
InitializeComponent();
labelVariable.Text = "";
}
private void textBoxes_TextChanged(object sender, EventArgs e)
{
txtOutput.Text = "";
labelVariable.Text = "";
Regex regex = new Regex(variableMarker + @"(.+)" + variableMarker);
if (regex.IsMatch(txtInput.Text))
{
Match thisMatch = regex.Match(txtInput.Text);
labelVariable.Text = thisMatch.Groups[1].ToString();
string output = txtValue.Text;
regex = new Regex(variableMarker + @"(.+)\[(?<from>[0-9$]+[-+]?[0-9$]*),(?<to>[0-9$]+[-+]?[0-9$]*)\]" + variableMarker);
if (regex.IsMatch(txtInput.Text))
{
thisMatch = regex.Match(txtInput.Text);
labelVariable.Text = thisMatch.Groups[1].ToString();
string posFrom = thisMatch.Groups["from"].ToString();
string posTo = thisMatch.Groups["to"].ToString();
posFrom = vorlage.calcString(posFrom.Replace("$", (txtValue.Text.Length - 1).ToString()));
posTo = vorlage.calcString(posTo.Replace("$", (txtValue.Text.Length - 1).ToString()));
output = "";
try
{
int intPosFrom = Convert.ToInt32(posFrom);
int intPosTo = Convert.ToInt32(posTo);
int intLength = intPosTo - intPosFrom + 1;
if (intLength + intPosFrom > txtValue.Text.Length)
intLength = txtValue.Text.Length - intPosFrom;
if (intLength > 0)
output = txtValue.Text.Substring(intPosFrom, intLength);
}
catch
{
output = txtValue.Text;
}
}
txtOutput.Text = output;
}
}
private void button2_Click(object sender, EventArgs e)
{
Clipboard.SetDataObject(txtInput.Text, true);
}
}
}