2017-05-23 2 views
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, ...], [...] 

"],"

후에 모든 요소를 ​​분할합니다.

도와주세요! 이 입력에

+0

왜이 태그가 PHP로 태그 되나요? – RiggsFolly

답변

1
// 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;"; 

날 (1/2/3 값을 각각 가진) 길이 (3)의 배열을 제공한다. 문이 한 번만 발생하는 경우 Where(...).First() 대신 Single(...)을 사용할 수도 있습니다.

+0

그리고'.Split (')')'와 같이 카테고리를 나눌 때 "split"메서드를 다시 사용할 수 있습니다. – TNation

+1

예, 가능성을 시험해보고 시도하십시오. 더 많은 유연성이 필요한 경우 언제든지 Regex.Match를 사용할 수 있습니다. – FDM