Wassup Jose Weblog nonsense at its best!

17Sep/091

Search & Replace

I had a few minutes this evening, so I whipped up a handy-dandy code sample. The sample illustrates how to use enumerations, switch statement, and the Regex.Replace method. It is not much, but I wanted to share the love. Tell me what ya think! Bruahaha.

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

public class Dinner
{
private enum AttendeeEnum
{
Gman,
Ninja,
Scooter
}
public static void Main()
{
Array attendees = Enum.GetValues(typeof(AttendeeEnum));
foreach(AttendeeEnum attendee in attendees)
{
Console.WriteLine("Attendee: " + getAttendeeName(attendee));
}
Console.ReadLine();
}

private static string getAttendeeName(AttendeeEnum attendeeName)
{
string name = string.Empty;
switch (attendeeName)
{
case AttendeeEnum.Gman:
case AttendeeEnum.Ninja:
{
name = attendeeName.ToString();
break;
}
case AttendeeEnum.Scooter:
{
name = Regex.Replace(attendeeName.ToString(), "coot", "tiff");
break;
}
default:
{
name = attendeeName.ToString();
break;
}
}
return name;
}
}

Comments (1) Trackbacks (0)
  1. ahahaha!
    That Scooter is a deadbeat!


Leave a comment

(required)

 

No trackbacks yet.