2016-03-29 11 views
0

Ich habe folgenden Code, aber ich möchte zweiten td-Wert, wie geht das? bitte hilfe.Wie bekomme ich zweiten Tag-Wert

string value = getBetween(xml, "<td class=\"statusValue\">", "</td>"); 

public static string getBetween(string strSource, string strStart, string strEnd) 
{ 
    int Start, End; 
    if (strSource.Contains(strStart) && strSource.Contains(strEnd)) 
    { 
     Start = strSource.IndexOf(strStart, 0) + strStart.Length; 
     End = strSource.IndexOf(strEnd, Start); 
     return strSource.Substring(Start, End - Start); 
    } 
    else 
    { 
     return ""; 
    } 
} 

siehe bitte Bild unten. enter image description here

Antwort

1

Sie können auch Regex verwenden, um alle Spiele zu bekommen:

public static string getBetween(string strSource, string strStart, string strEnd) 
{ 
    string pattern = string.Format("{0}((.|\n|\r)*?){1}", strStart, strEnd); 
    Regex r = new Regex(pattern); 
    var matchCollection = r.Matches(strSource); 
    //you can iterate through collection 

    foreach (Match match in r.Matches(strSource)) 
    { 

     string textBetweenTags = match.Groups[1].ToString(); 
     //your logic here 
    } 

    //or return second value you want 
    if (matchCollection.Count >= 2) 
    { 
     return matchCollection[1].Groups[1].ToString(); 
    } 
    else 
    { 
     return ""; 
    } 
} 
+0

seine Show null; ( –

+0

können Sie Ihre XML in Text geben Sie bitte – denisv

+0

ich habe xml html nicht –

Verwandte Themen