The following code can be used to extract the value of variable from
Text
of
TextBox1
. Since, the variable name is taken from
Index 10
using
a.SubString(10)
it is better to use
a.StartsWith
method instead of
a.contains
method.
For Each a As String In TextBox1.Text.Split(ControlChars.Lf)
If a.StartsWith("print_var ") Then
TextBox2.Text &= vbCrLf + System.Text.RegularExpressions.Regex.Match( _
TextBox1.Text, String.Format("(?<=#{0}: ).*", a.Substring(10)), _
RegexOptions.CultureInvariant).Value
End If
Next
The
(?<=#{0}: )
pattern matches
#x:
, but excludes it from the
Match.Value
.
[Edit] C# code added as sought in the comment to this solution [/Edit]
Please try the following code:
foreach (string a in TextBox1.Text.Split('\n')) {
if (a.StartsWith("print_var ")) {
TextBox2.Text += "\r\n" + System.Text.RegularExpressions.Regex.Match(TextBox1.Text, string.Format("(?<=#{0}: ).*", a.Substring(10)), RegexOptions.CultureInvariant).Value;
}
}