1

I'm returning some data as string and want to get some selected data from that string (b/w Form tag).

string ReturnURlData = "hbhjbhjb hjbhjbhjb hjbhj <br/>vhbvhbhjjjbjjbhj jknknkjk

<form name=cart action='cart.asp'  önSubmit='return checkAllQuantities();' method=post> 

// --------I want to get data from here to

<tr>
    <td class="ROC_SellrCartRow">Menu18</td>
    <td class="ROC_SellrCartRow">Burger Quarter Pounder with Cheese</td>
    <td class="ROC_SellrCartRow"><input type=hidden id=Hidden5 value=0><input type=hidden id=6maxQuantity value=9999999><input type=hidden id=6minQuantity value=1><input type=hidden name=6basketitemid value=90265465><input class=ROC_quantityfield type=text  id=6quantity onClick='return ChangeAction(1);' onfocus='return ChangeAction(1);' onKeyUp='userChangedQuantity(6,false);' onChange='userChangedQuantity(6,true);' maxlength=6 size=3 name=6newquantity value=8></input></td>
    <td class="ROC_SellrCartRow">£23.20</td>
    </tr>

// -------- to here (END)

<form> hjbhjbhjhjhbhjubhjuubhbhjubhjubu hbhjhuh  ";

I know it's a minor task & I can do this by 3-4 step. But I want to know that can we do this in single query. Any suggestions really appreciate.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
John Cena
  • 45
  • 4

2 Answers2

1

You can use HTmlAgilityPack. Its very easy to use. This should do the trick.

HtmlDocument doc = new HtmlDocument();
 doc.LoadHtml(t);

 HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//td[@class='ROC_SellrCartRow']");    

 string result;
 foreach (HtmlNode item in nodes) 
       result += item.InnerText;
Kemal Can Kara
  • 416
  • 2
  • 15
1

Hi you can do like this :

string s = "Abc Pqr Xyz";
s = getBetween(s, "A", "z");

Use below function :

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 "";
}

}

John
  • 697
  • 4
  • 13
  • 27