Skip to content

Instantly share code, notes, and snippets.

Last active December 21, 2015 05:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rtpHarry/6254339 to your computer and use it in GitHub Desktop.
Code sample written for a StackOverflow question to show how to build alpha link roulette html by extracting and grouping the first letters of a list of jobs.
public class GetAlphaRouletteLinks
// Outputs markup like this:
// <a href="#rouletteA">A</a> | <a href="#rouletteB">B</a> | <a href="#rouletteC">C</a> | <a href="#rouletteD">D</a> | <a href="#rouletteE">E</a> | <a href="#rouletteF">F</a> | G | <a href="#rouletteH">H</a> | <a href="#rouletteI">I</a> | <a href="#rouletteJ">J</a> | K | <a href="#rouletteL">L</a> | <a href="#rouletteM">M</a> | <a href="#rouletteN">N</a> | <a href="#rouletteO">O</a> | <a href="#rouletteP">P</a> | <a href="#rouletteQ">Q</a> | <a href="#rouletteR">R</a> | <a href="#rouletteS">S</a> | <a href="#rouletteT">T</a> | <a href="#rouletteU">U</a> | V | <a href="#rouletteW">W</a> | X | Y | Z
// Notice how it skips the link for any letters that don't have jobs starting with that letter eg:
// <a href="#rouletteW">W</a> | X | Y | Z
public string GetAlphaRouletteLinksHtmlMarkup()
var JobList = new List<String>() {
"American Chemical Society",
"America's Job Bank",
"Art Careers",
"Asian MBA",
"Back Door Jobs",
"Career Search",
"Careers 2005",
"City of Evansville jobs",
"College Recruiter",
"Conservation Job Board",
"Cuyahoga County Public Library",
"Dentist Jobs Help",
"Evansville Courier & Press Classifieds",
"Federal Government Jobs",
"Indiana Health Careers",
"Indiana Job Central",
"Indiana Youth Institute",
"Inside Jobs",
"Jackson County Industrial Development Corporation",
"Job Application Center",
"Job Search USA",
"Job Seeker's Bookmarks",
"Jobs in Indianapolis Web site",
"Journal of Young Investors",
"Learn More Indiana",
"Louisville, KY jobs",
"News-Line Communications",
"On-Line Career Center",
"Online Recruiters Directory",
"Quintessential Careers",
"Riley Guide",
"SallieMae True Careers",
"Simply Hired",
"State government job opportunities",
"Student Employment Opportunities",
"Teacher Jobs Help",
"The Ladders Career Advice",
"U. S. Department of State",
"Work In Sports",
var letters = from alpha in "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z".Split(',')
let firstLetters = (from job in JobList
orderby job
group job by job[0].ToString().ToUpper() into firstLetters
select firstLetters.Key)
select new
Letter = alpha,
IsLink = firstLetters.Contains(alpha)
StringBuilder outputHtml = new StringBuilder();
foreach (var item in letters)
if (item.IsLink)
// add html
outputHtml.AppendFormat("<a href=\"#roulette{0}\">{1}</a> | ", item.Letter, item.Letter);
// no html
outputHtml.Append(" | ");
return outputHtml.ToString().TrimEnd(" | ".ToCharArray());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment