Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I am trying to get latest news for a blog. Data comes from a website as a string something like this;

HTML
<li> some text some tag something about the news </li>
.
.
.
.
.
.
.
<li> some other text some other tag something about the other news </li>


I need to split them as item.

ie. one
  • news item. So that I can put them in a foreach loop then create my own css.

    İs there a way to split ? startWith this and EndWith this?
    Posted
    Comments
    Krunal Rohit 17-Sep-15 4:13am    
    It is coming as item i.e. <li> then why you want to split it?

    -KR
    FoxRoot 17-Sep-15 6:30am    
    because I want to remove li tags.
    Patrice T 17-Sep-15 4:40am    
    Read documentation/follow tutos about regex
    FoxRoot 17-Sep-15 6:30am    
    Thank you.

    You could use a regex:
    (?<=\<li\>).*?(?=\</li\>)
     
    Share this answer
     
    Comments
    FoxRoot 17-Sep-15 6:30am    
    Thanks. It works fine. I used second solution.
    C#
    var result = (new Regex(@"<li>(.*?)<li>")).Matches(str).Cast<Match>()
                   .Select(m => m.Value)    
                   .ToArray()
    	           .Select(x => x.Replace("<li>", "").Replace("</li>", ""));

    it returns the contents of <li><li> as a string collection.
    if you want to keep the <li><li> just delete the last select line
     
    Share this answer
     
    v5
    Comments
    FoxRoot 17-Sep-15 6:30am    
    Thanks. It works fine.

    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