-3

我的程序应该在源文本框中找到并在找到 aConsole.WriteLine("之后开始读取字符串,然后将捕获的字符串存储在变量中。例如,如果输入是:"")

Console.WriteLine("Hello World")

那么变量的值应该是Hello World

帮助将不胜感激。

4

1 回答 1

2
string yourInput = ...
var result = Regex.Match(yourInput, "Console.WriteLine[(]\"(.*?)(?<!\\\\)\"[)]").Groups[1].Value;

一个小测试:

string yourInput = "Console.WriteLine(\"\\\") Yeahhh\")"; 
yourInput += "Console.WriteLine(\"At least Regex can handle \"this\"\")";
yourInput += "Console.WriteLine(\"Although \"Regex\" is afraid of parsing \"text\" with nested elements\")";
var matches = Regex.Matches(yourInput, "Console.WriteLine[(]\"(.*?)(?<!\\\\)\"[)]");
foreach (Match m in matches)
    System.Diagnostics.Debug.Print(m.Groups[1].Value);

输出

\") Yeahhh
At least Regex can handle "this"
Although "Regex" is afraid of parsing "text" with nested elements
于 2013-08-31T02:11:21.800 回答