Click here to Skip to main content
13,400,476 members (36,351 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 5 Aug 2014

Convert a list of names to HTML Wikipedia links

, 8 Aug 2014
Rate this:
Please Sign up or sign in to vote.
How to convert a list of names to the HTML needed to create a link to the corresponding Wikipedia articles

The Eagles Have Landed

If you have a list of names of famous people such as this:

  • Glenn Frey
  • Don Henley
  • Bernie Leadon
  • Randy Meisner
  • Joe Walsh
  • Timothy B. Schmit
  • Don Felder
  • Jackon Browne
  • J.D. Souther may want to linkify the names to point to their respective wikipedia articles. To do so is not difficult, because wikipedia follows a standard format for the URLs for its entries - in most cases for proper names, it simply replaces the space between the first and last name with an underscore, like so: "Chris Hillman" becomes "Chris_Hillman". The link for the Byrdman of Bakersfield (poetic license) is: href=""

There's always an exception, though (there may be an exception to that rule, too, which would be nice). In this case, though, there's not an exception to the exception rule (oh, pooh!), so we have to watch out for "special cases" such as names with initials. In this case, wikipedia retains the period but places an underscore after it, such as:

Still, programatically transforming names into the accepted format is pretty easy. Here's some example code; you can pass the name of any person with a wikipedia page to the Wikipidify() method to get back the appropriate HTML for the link to that wikipedia page.

The sample code uses names of current and former members of The Eagles (the Eagles from Southern California, not the Philadelphia Eagles, football fans), along with the names of some affiliated/associated people, such as "The Fifth Eagle," Jackson Browne, as well as songwriter J.D. Souther. A fictional character, Rupert Pupkin (The King of Comedy ) is also included to show what happens when a person in the list does not have a wikipedia page (the link is created fine, but clicking it takes you to a "Winchester Mystery page").

private void buttonYourLip_Click(object sender, EventArgs args)
    List<string> eaglets = new List<string>();
    eaglets.Add("Glenn Frey");
    eaglets.Add("Don Henley");
    eaglets.Add("Bernie Leadon");
    eaglets.Add("Randy Meisner");
    eaglets.Add("Joe Walsh");
    eaglets.Add("Timothy B. Schmit");
    eaglets.Add("Don Felder");
    eaglets.Add("Jackon Browne");
    eaglets.Add("J.D. Souther");
    eaglets.Add("Rupert Pupkin");

    List<string> htmlifiedEaglets = new List<string>();

    foreach (var eaglet in eaglets)
    System.IO.File.WriteAllLines(@"C:\alreadyGone\eaglets.txt", htmlifiedEaglets);

private string Wikipidify(string eaglet)
    const String wikipediaTemplate = "<a href=\"{0}\"  target=\"_blank\">{1}</a>";
    string HTMLifiedEaglet = String.Empty;
    string underlinedEaglet = String.Empty;
    // make sure each "." is followed by a space
    underlinedEaglet = eaglet.Replace(".", ". ");
    // ...if there are now two spaces anywhere (such as where a period was already followed by a space), make them one 
    underlinedEaglet = underlinedEaglet.Replace("  ", " "); 
    // Now replace the single space[s] with underscore[s]
    underlinedEaglet = underlinedEaglet.Replace(" ", "_");
    HTMLifiedEaglet = String.Format(wikipediaTemplate, underlinedEaglet, eaglet);
    return HTMLifiedEaglet;

As you can see, the results are saved to a file. The file created for the list shown above looks like this:

<a href="" target="_blank">Glenn Frey</a> <a href="" target="_blank">Don Henley</a> <a href="" target="_blank">Bernie Leadon</a> <a href="" target="_blank">Randy Meisner</a> <a href="" target="_blank">Joe Walsh</a> <a href="" target="_blank">Timothy B. Schmit</a> <a href="" target="_blank">Don Felder</a> <a href="" target="_blank">Jackson Browne</a> <a href="" target="_blank">J.D. Souther</a> <a href="" target="_blank">Rupert Pupkin</a>

If you don't want to take the time to add this code to a project just now, you can see the list of these generated links here



As you might surmise, I am a big fan of the Eagles; I bought their debut (eponymous) LP when it was still warm to the touch - in my birthplace of Fort Bragg, California. Although nobody asked me, I feel their best album - a masterpiece! - is the concept album "Desperado" (it also has the best back cover photo of all time).

Fade Out


I like almost everything the Eagles ever did, through all their personnel changes, with one blatant and glaring exception: "The Best of My Love" is one of the lamest songs I've ever heard, vying with the Commodore's "Three Times a Lady" for the most gag-worthy song of all time from otherwise good-great bands. If you agree with me that they sound like they've been hypnotized by Barry Manilow on that tune, go to your window, open it, lean out and shout at the tip-top of your voice: "I'm fed up, and I'm not gonna take it any more! No more plodding, saccharine love songs by people who can do so much better!!!"

Not Fade Away


You can purchase any of the Eagles albums from here


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


About the Author

B. Clay Shannon
Founder Across Time & Space
United States United States
I am in the process of morphing from a software developer into a portrayer of Mark Twain. My monologue (or one-man play, entitled "The Adventures of Mark Twain: As Told By Himself" and set in 1896) features Twain giving an overview of his life up till then. The performance includes the relating of interesting experiences and humorous anecdotes from Twain's boyhood and youth, his time as a riverboat pilot, his wild and woolly adventures in the Territory of Nevada and California, and experiences as a writer and world traveler, including recollections of meetings with many of the famous and powerful of the 19th century - royalty, business magnates, fellow authors, as well as intimate glimpses into his home life (his parents, siblings, wife, and children).

Peripatetic and picaresque, I have lived in eight states; specifically, besides my native California (where I was born and where I now again reside) in chronological order: New York, Montana, Alaska, Oklahoma, Wisconsin, Idaho, and Missouri.

I am also a writer of both fiction (for which I use a nom de plume, "Blackbird Crow Raven", as a nod to my Native American heritage - I am "½ Cowboy, ½ Indian") and nonfiction, including a two-volume social and cultural history of the U.S. which covers important events from 1620-2006:

You may also be interested in...

Comments and Discussions

QuestionPeople WIth Identical Names Pin
PeejayAdams11-Aug-14 4:00
memberPeejayAdams11-Aug-14 4:00 
QuestionAnd what about other names? Pin
Pete O'Hanlon10-Aug-14 12:01
protectorPete O'Hanlon10-Aug-14 12:01 
AnswerRe: And what about other names? Pin
B. Clay Shannon10-Aug-14 19:15
professionalB. Clay Shannon10-Aug-14 19:15 
GeneralMy vote of 5 Pin
Volynsky Alex8-Aug-14 22:52
professionalVolynsky Alex8-Aug-14 22:52 
SuggestionTypo? - You are replacing a space with a space! Pin
DaveAuld7-Aug-14 20:11
protectorDaveAuld7-Aug-14 20:11 
GeneralRe: Typo? - You are replacing a space with a space! Pin
B. Clay Shannon7-Aug-14 20:20
professionalB. Clay Shannon7-Aug-14 20:20 
GeneralRe: Typo? - You are replacing a space with a space! Pin
DaveAuld7-Aug-14 20:28
protectorDaveAuld7-Aug-14 20:28 
SuggestionAPI addition Pin
pritaeas6-Aug-14 22:35
memberpritaeas6-Aug-14 22:35 
GeneralRe: API addition Pin
Florian Rappl9-Aug-14 1:20
mvpFlorian Rappl9-Aug-14 1:20 
GeneralRe: API addition Pin
B. Clay Shannon9-Aug-14 4:08
professionalB. Clay Shannon9-Aug-14 4:08 
GeneralRe: API addition Pin
.:floyd:.9-Aug-14 9:04
member.:floyd:.9-Aug-14 9:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180218.2 | Last Updated 8 Aug 2014
Article Copyright 2014 by B. Clay Shannon
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid