1

I have a file thats exported with a ton of lines. I want to be able to parse the file into a neat order that I can easily use.

I have a sample string here:

<a href="http://www.foxnews.com/us/2010/07/28/cemetery-allows-father-war-veteran-fly-flag-grave/?test=latestnews">deal reached on cemetery flags</a>
| <a href="#" onclick="foxgrabplayer('4295654','','grave insult to grieving family');return false;"><img src="/i/redes/icon-video.gif"></a><br>
- <a href="http://www.foxnews.com/politics/2010/07/27/obama-missing-historic-boy-scout-jamboree-fundraisers-view-taping/">obama skips out on scouts for 'the view'</a><br>
- <strong class="em">you decide: </strong><a href="http://www.foxnews.com/opinion/2010/07/27/decide-right-obama-miss-boy-scout-jamboree/">right call?</a></li>"

All of that is 1 line. I'd want it to output like the following:

http://www.foxnews.com/us/2010/07/28/cemetery-allows-father-war-veteran-fly-flag-grave|Deal reached on cemetery flags  
http://www.foxnews.com/politics/2010/07/27/obama-missing-historic-boy-scout-jamboree-fundraisers-view-taping|obama skips out on scouts for 'the view

sort of www|description for every href in the line. Hope this makes sense!

3
  • Is the example string supposed to be valid HTML? Commented Jul 28, 2010 at 19:50
  • Yes, i had to chop it up because i did not know how to get it to display full string on SOF Commented Jul 28, 2010 at 19:54
  • At the end of the day I am just trying to pull the hyperlink and description of the link. Commented Jul 28, 2010 at 20:02

2 Answers 2

1

I really hate to say this but. Use regular expressions. href="(.*?)" should get you all the hrefs. May need a bit of tweaking to eliminate things you don't want. Here is a decentish article on implementation http://oreilly.com/windows/archive/csharp-regular-expressions.html

Sign up to request clarification or add additional context in comments.

Comments

0

Take a look at the Html Agility Pack. The first example deals with hrefs: http://htmlagilitypack.codeplex.com/wikipage?title=Examples&referringTitle=Home.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.