Small message parser, whats bad?
<p>i made a small parser that will go though a message and replace $user with a certain user and so on.</p>

<p>besides the basic keywords, i wanted it to replace dates like this:
$datemo10 with todays date plus 10 months
$datedd03 with todays date plus 3 days
$datehh07 with todays date plus 7 hours
$datemm12 with todays date plus 12 minutes
$datess15 with todays date plus 15 seconds</p>

<p>This is what i got working..</p>

<pre><code>    const string Identifier = "$";
    const string TimeFormat = "HH:mm:ss dd-MM-yyyy";

    public static string Encode(string Author, string Recipent, string input)
    {
        Dictionary&lt;string, string&gt; keywords = new Dictionary&lt;string, string&gt;();
        keywords.Add("bye", "With kind regards " + identify("me"));
        keywords.Add("user", Recipent);
        keywords.Add("me", Author);
        keywords.Add("now", DateTime.Now.ToString(TimeFormat));
        keywords.Add("date", "");

        string result = input;
        foreach (KeyValuePair&lt;string, string&gt; keyword in keywords)
        {
            if (keyword.Key.ToLower() == "date")
            {
                int addedLength = 0;
                foreach (Match match in Regex.Matches(input, "\\" + identify(keyword.Key)))
                {
                    string mode = input.Substring(match.Index + addedLength + match.Length, 2);
                    string stringInteger = input.Substring(match.Index + addedLength + match.Length + 2, 2);
                    int integer;
                    if (int.TryParse(stringInteger, out integer) &amp;&amp; !mode.Contains(" "))
                    {
                        if (mode == "ss")
                        {
                            string dateTime = DateTime.Now.AddSeconds(Convert.ToDouble(integer)).ToString(TimeFormat);
                            input = input.Remove(match.Index + addedLength, match.Length + 4);
                            input = input.Insert(match.Index + addedLength, dateTime);
                            addedLength += (dateTime.Length - (match.Length + 4));
                        }
                        else if (mode == "mm")
                        {
                            string dateTime = DateTime.Now.AddMinutes(Convert.ToDouble(integer)).ToString(TimeFormat);
                            input = input.Remove(match.Index + addedLength, match.Length + 4);
                            input = input.Insert(match.Index + addedLength, dateTime);
                            addedLength += (dateTime.Length - (match.Length + 4));
                        }
                        else if (mode == "hh")
                        {
                            string dateTime = DateTime.Now.AddHours(Convert.ToDouble(integer)).ToString(TimeFormat);
                            input = input.Remove(match.Index + addedLength, match.Length + 4);
                            input = input.Insert(match.Index + addedLength, dateTime);
                            addedLength += (dateTime.Length - (match.Length + 4));
                        }
                        else if (mode == "dd")
                        {
                            string dateTime = DateTime.Now.AddDays(Convert.ToDouble(integer)).ToString(TimeFormat);
                            input = input.Remove(match.Index + addedLength, match.Length + 4);
                            input = input.Insert(match.Index + addedLength, dateTime);
                            addedLength += (dateTime.Length - (match.Length + 4));
                        }
                        else if (mode == "mo")
                        {
                            string dateTime = DateTime.Now.AddMonths(integer).ToString(TimeFormat);
                            input = input.Remove(match.Index + addedLength, match.Length + 4);
                            input = input.Insert(match.Index + addedLength, dateTime);
                            addedLength += (dateTime.Length - (match.Length + 4));
                        }
                        else if (mode == "yy")
                        {
                            string dateTime = DateTime.Now.AddYears(integer).ToString(TimeFormat);
                            input = input.Remove(match.Index + addedLength, match.Length + 4);
                            input = input.Insert(match.Index + addedLength, dateTime);
                            addedLength += (dateTime.Length - (match.Length + 4));
                        }
                    }
                }
            }
            else
            {
                input = Regex.Replace(input, "\\" + identify(keyword.Key), keyword.Value);
            }
        }

        return input;
    }

    protected static string identify(string val)
    {
        return Identifier + val;
    }
</code></pre>

<p>I feel fine about keeping the keywords that needs to be replaced in a dictionary, but i really dont like the way im parsing and replacing the dates.</p>

<p>But as im pretty new to the whole programming world, this is the only way i was able to make it work. Though im perfectly able to see why it could be so much better, if you have any idea on how to make it work in a less hacky way, please tell me :)</p>

<p>Tear it apart, but please do so in a constructive matter.
How can i make it better?</p>

<p>I know there is quite a bit repetitive code.. Shhh</p>

<p>Thanks :)</p>
