Split String Html

0

Personal I have an HTML with the following code:

<div class="page">
...Conteúdo1
</div>

<div class="page">
...Conteúdo2
</div>

<div class="page">
...Conteúdo3
</div>

The "page" class it creates a background as if it were an A4 sheet, so that the content is placed inside it, the following happens, that when I bring the whole HTML into a string they see it in a single string, only I I needed for each page div to generate an image individually, but I have no idea how I could do to separate each div into a different string. If anyone can help.

string HTMLemString = RenderizaHtmlComoString("~/Views/Item/Item.cshtml", id);

The above code is where you bring the entire html page.

    
asked by anonymous 17.03.2017 / 14:31

2 answers

0

This code does magic using regular expressions

var texto = "<div class='page'>...Conteúdo1</div>";
texto += "<div class='page'>...Conteúdo2</div>";
texto += "<div class='page'>...Conteúdo3</div>";
string pattern = "<div class='page'>(.*?)<\/div>";
MatchCollection matches = Regex.Matches(texto, pattern);

foreach (Match m in matches)
{
    MessageBox.Show(m.ToString());
}

Each iteration of the foreach loop is a 'page'

    
17.03.2017 / 17:51
0

Well, maybe this solution is a bit forced, but it works ..

        string split = "<div class=\'page\'>";
        List<string> div = System.Text.RegularExpressions.Regex.Split(HTMLemString, split, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Where(w=>!string.IsNullOrEmpty(w)).Select(s=> split + s).ToList();
    
17.03.2017 / 15:12