Some things from my application I can't talk about

I'm uber behind on a project but will show off some stuff I love.  I really, really love Regular Expressions too.

New feature in .net 3.5

Poll poll = new Poll {
    PollName = breakdown[1],
    UserId = tweet.User.Id,
    TweetId = tweet.Id,
    UserName = tweet.User.Name};

And processing the votes

public void ProcessParameterList(string parameterList)
{
    PollParameterList = parameterList;
    // currently supported
    // 1-10 \d-\d
    // a,b,c,d comma delimited.

    // check for 10-20
    if(Regex.IsMatch(PollParameterList, "\\d+-\\d+"))
    {
        string[] items = Regex.Split(PollParameterList, "-");
        if( items.Length == 2)
        {
            int endAt = int.Parse(items[1]); // I know due to regex they will be numbers
            int startAt = int.Parse(items[0]);
            if (startAt > endAt)
            {
                int temp = endAt;
                endAt = startAt;
                startAt = temp;
            }

            for (int i = startAt; i <= endAt; i++)
                BalletParameters.Add(i.ToString());
        }
    }
    // check for a,b,c,d
    else if(Regex.IsMatch(PollParameterList, ","))
    {
        string[] items = Regex.Split(PollParameterList, ",");
        foreach (var item in items)
            BalletParameters.Add(item.Trim());
    }
}

Using the TwitterLib with some tweaks from Witty.  Gotta figure out how to contribute it back in.

No comments posted yet.

Post a Comment

Please add 5 and 3 and type the answer here: