Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hi sir,
   I am getting the string like below, i need to get only the first <p> </p> tag contents. Kindly give me the solution for this problem.



Input:
********

<p>You should step up and use some of this amazing energy to take action -- the world needs what you've got! It's a really good day for some parties, startups and other fun things that just need some initiative.</p><p>More horoscopes! Check your , , , , , ...</p><p>Today's Free Sample Reading: </p><p></p>



Output:
**********

<p>You should step up and use some of this amazing energy to take action -- the world needs what you've got! It's a really good day for some parties, startups and other fun things that just need some initiative.</p>
Posted

Hi,
try this.
C#
string value = "<p>You should step up and use some of this amazing energy to take action -- the 
                world needs what you've got! It's a really good day for some parties, startups and 
                other fun things that just need some initiative.</p><p>More horoscopes! Check your 
                , , , , , ...</p><p>Today's Free Sample Reading: </p><p></p>";

string[] spltvalue = System.Text.RegularExpressions.Regex.Split(value,"</p>");
string finalstringvalue = spltvalue[0] + "</p>";

hope it helps you.
 
Share this answer
 
v3
Try using Jquery ..



XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="jquery-1.10.2.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(function () {

            var contents = $('#divContainer p').eq(0).text();
            alert(contents);

        });






    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="divContainer">
        <p>
            You should step up and use some of this amazing energy to take action -- the world
            needs what you've got! It's a really good day for some parties, startups and other
            fun things that just need some initiative.</p>
        <p>
            More horoscopes! Check your , , , , , ...</p>
        <p>
            Today's Free Sample Reading:
        </p>
        <p>
        </p>
    </div>
    </form>
</body>
</html>
 
Share this answer
 
Hi Prabu,

You could try this

XML
string input = @"<p>You should step up and use some of this amazing energy to take action -- the world needs what you've got! It's a really good day for some parties, startups and other fun things that just need some initiative.</p><p>More horoscopes! Check your , , , , , ...</p><p>Today's Free Sample Reading: </p><p></p>";

string[] output = input.Split(new string[] {"</p>"}, StringSplitOptions.RemoveEmptyEntries);
output[0] += "</p>";

Now in output[0] you will get <p>You should step up and use some of this amazing energy to take action -- the world needs what you've got! It's a really good day for some parties, startups and other fun things that just need some initiative.</p>

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v4
Hi Prabu,

You could try this

XML
string input = @"<p>You should step up and use some of this amazing energy to take action -- the world needs what you've got! It's a really good day for some parties, startups and other fun things that just need some initiative.</p><p>More horoscopes! Check your , , , , , ...</p><p>Today's Free Sample Reading: </p><p></p>";

string[] output = input.Split(new string[] {"</p>"}, StringSplitOptions.RemoveEmptyEntries);
<pre>output[0] += "</p>";
</pre>

Now in output[0] you will get "<code>&lt;p&gt;You should step up and use some of this amazing energy to take action -- the world needs what you've got! It's a really good day for some parties, startups and other fun things that just need some initiative.</code>

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900