You must Sign In to post a response.
  • Category: HTML

    Remove unwanted spaces and lines in tags inside div in string result..?

    Hi All,

    I have one small issue,

    This is my Div.. in string object...


    string result="<div class="clearBlock">
    <ul class="scroll">

    <li>
    <div class="clearWidth MRGT20PX">
    <div class="floatLeft LineHeight33">
    <i>
    p530777 Says</i></div>
    <div class="date floatRight">
    05-28-2015</div>
    </div>
    </li>
    </ul>
    </div>"


    but i want to remove unwanted spaces between tags and lines and i need the result like below.


    string result="<div class="clearBlock"><ul class="scroll"><li><div class="clearWidth MRGT20PX"><div class="floatLeft LineHeight33"><i>p530777 Says</i></div><div class="date floatRight">05-28-2015</div></div></li></ul></div>"


    If any one knows how to do this please help me...
  • #759210
    Try the below piece of Code:

    string linebreak= ((char) 0x2028).ToString();
    string paragraphbreak = ((char)0x2029).ToString();
    result = result.Replace("\r\n", string.Empty);
    result = result.Replace("\n", string.Empty);
    result = result.Replace("\r", string.Empty);
    result = result.Replace(linebreak, string.Empty);
    result = result.Replace(paragraphbreak , string.Empty);

  • #759213
    Hello Naveensanagasetti,

    You can use below Java Script code to remove unwanted space and lines in html tags:

    var str = "<div class="clearBlock">
    <ul class="scroll">

    <li>
    <div class="clearWidth MRGT20PX">
    <div class="floatLeft LineHeight33">
    <i>
    p530777 Says</i></div>
    <div class="date floatRight">
    05-28-2015</div>
    </div>
    </li>
    </ul>
    </div>";
    var newStr = str.replace(/\s+/g, '');

    Output:
    <div class="clearBlock"><ul class="scroll"><li><div class="clearWidth MRGT20PX"><div class="floatLeft LineHeight33"><i>p530777 Says</i></div>
    <div class="date floatRight">05-28-2015</div></div></li></ul></div>


    If you are using php you can use the below code:

    function removeWhitespace($buffer)
    {
    return preg_replace('/\s+/', ' ', $buffer);
    }

    ob_start('removeWhitespace');

    <!DOCTYPE html>
    <html>
    <head></head>
    <body></body>
    </html>

    ob_get_flush();

    Output:
    <!DOCTYPE html><html><head></head><body></body></html>

    Hope this will help you.
    Mark the answer if it helped you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762983
    You can use this trick to get rid of the space:

    HTML:

    <div id="test">
    <a href="/blog/">Home</a>
    <a href="/about/">About</a>
    <a href="/contact/">Contact</a>
    </div>
    CSS:

    #test { font-size:0; }
    #test a { font-size:16px; background:yellow; }


  • Sign In to post your comments