Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 12, 2015 @ 12:54
    Fuji Kusaka
    0

    Splitting content in 2 different container

    Hi,

    Can someone explains what is the best way of splitting RTE content text in 2 seperate div container ?

    Since am working with a very long text container we would like to trim 0-450 characters in one div container and from 451 - 950 in another div container.

    This is how my razor file looks like atm 

     var desc = @x.GetProperty("reasonDescription").Value.ToString();
    @if(desc.ToString().Length > 950){
    <span class="1">@Html.Raw(desc.Substring(0,450).</span>
    <span class="2"><br/><a href="#">Read More</a></span>
    }

     

    Any suggestions on how to get this working ?

  • Tobias Klika 101 posts 570 karma points c-trib
    Feb 12, 2015 @ 13:42
    Tobias Klika
    0

    Pretty hard to split HTML in 2 equal parts, but one thing is for sure: Substring won't be your friend here ;-)

    What's your browser requirement? Because you could easily achieve this with CSS columns (browser support). See here for introduction.
    In case you need to split it without CSS, you will need a RegEx or parse the entire HTML (I would prefer RegEx).
    The problem with both solutions is, that it's pretty impossible to split exactly it char 450, because this char could be a tag itself?! Or it could be text within a tag. So if you split it, you will have to close the tag and re-open it in the next part again.

    That's why I think CSS columns are the best solution here, as the browser can handle it itself.

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 13, 2015 @ 06:54
    Fuji Kusaka
    0

    Hi Tobias,

    True splitting those RTE content not very handy and practical. But yes i will give a try to css columns the only thing is IE not supporting it properly.

    Thanks,

Please Sign in or register to post replies

Write your reply to:

Draft