Q:

String Regex Help C#

I'm trying to create a regex that reads a string, and if the last character is something like !"£$% etc, it ignores the last character, reads the string (to allow my code to look it up in a dictionary class) and then outputs the string, with the character on the end it ignored. Is this actually possible, or do I have to just remove the last character?
So far...
foreach(var line in yourReader)
{
    var dict = new Dictionary<string,string>(); // your replacement dictionaries
    foreach(var kvp in dict)
    {
        System.Text.RegularExpressions.Regex.Replace(line,"(\s|,|\.|:|\\t)" + kvp.Key + "(\s|,|\.|:|\\t)","\0" + kvp.Value + "\1");
    }
}

I've also been told to try this
var trans = textbox1.Text;

foreach (var kvp in d) //d is my dictionary so use yours
{
     trans = trans.Replace(kvp.Key, kvp.Value);
}

textbox2.Text = trans;

but have literally no idea what it does

A:

I didn't find any point using Regex, so I hope this will help:
        const int ARRAY_OFFSET = 1;

        List<char> ForbiddenChars = new List<char>()
        {
            '!', '@', '#', '$', '%', '^', '&', '*', '£' //Add more if you'd like
        };

        string myString = "Hello World!&";

        foreach (var forbiddenChar in ForbiddenChars)
        {
            if (myString[myString.Length - ARRAY_OFFSET] == forbiddenChar)
            {
                myString = myString.Remove(myString.Length - ARRAY_OFFSET);
                break;
            }
        }

Edit:
I checked the old code, and it had a problem: when the string's last "forbidden" characters were in order of the ForbiddenChars array it deleted all of them. if your string was "Hello World&!" it would delete both the ! and &. so I set a break; and it won't be a problem anymore.

