Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在字符串中查找数组_C#_Selenium_Web_Webdriver - Fatal编程技术网

C# 在字符串中查找数组

C# 在字符串中查找数组,c#,selenium,web,webdriver,C#,Selenium,Web,Webdriver,我正在使用C#中的Selenium API。 我试着读一个脚本并从中获得所需的值 string attackable_villages = web.FindElement(By.XPath("//*[@id='content_value']/script[1]")).GetAttribute("innerHTML"); richTextBox1.Text = attackable_villages; 我得到的结果是: result.scrollBound = { x_min: 0,

我正在使用C#中的Selenium API。 我试着读一个脚本并从中获得所需的值

string attackable_villages = web.FindElement(By.XPath("//*[@id='content_value']/script[1]")).GetAttribute("innerHTML");
richTextBox1.Text = attackable_villages;
我得到的结果是:

result.scrollBound = {
    x_min: 0,
    x_max: 999,
    y_min: 0,
    y_max: 999
};

result.tileSize = [53, 38];

result.screenKey = 'bf14559d';
result.topoKey = 4133874391;
还有更多

但有一点:

result.thisiswhatiwant= [1value1, 1value2, 1value3, 1value4..], [2value1, 2value2, 2value3, ...], [...]
我如何在没有剩余元素的情况下获取该数组,并在
“],”之后拆分所有元素

我希望你能帮助我

// Split the script in its individual statements
var splitArray = script.Split(';');
// Get the statement you're interested in
var line = splitArray.Where(x => x.Contains("result.thisiswhatiwant")).First();         
// Remove all characters except numbers and commas, then split by comma       
var values = Regex.Replace(line, "[^0-9,]", string.Empty).Split(',');
使用此输入进行测试:

 string script = "test; result.thisiswhatiwant=[1,2,3]; three;";
给我一个长度为3的数组(值分别为1/2/3)。
如果语句只出现一次,您也可以使用
Single(…)
而不是
Where(…).First()

为什么用PHP标记?我可以在我的“行”中再次使用split方法,用类似的
来拆分类别。split(']
?是的,尝试尝试各种可能性,您应该可以做到这一点。如果需要更大的灵活性,可以始终使用Regex.Match。