The following uses Regex to construct the lesson code from various formats. I've also expanded the solution to cater for other lessons e.g. HIST for History, ENGL for English and also to cater for non-upper case entries.
I've used a string array for my checking
private void button2_Click(object sender, EventArgs e)
{
string[] lessons = {"....", "hist=101", "MATH103","MATH-103", "MATH 103", "MATH_103", "MATH--101", "engl 100"};
foreach (string singleLesson in lessons)
{
Match m = Regex.Match(singleLesson, @"\d+", RegexOptions.IgnoreCase);
Match n = Regex.Match(singleLesson, @"\b[A-Z|a-z]*", RegexOptions.IgnoreCase);
if (m.Success && n.Success )
{
string lesson = n.ToString().ToUpper() + m.ToString();
Debug.Print(lesson);
}
else
Debug.Print("Invalid Entry");
}
Output:
Invalid Entry<br />
HIST101<br />
MATH103<br />
MATH103<br />
MATH103<br />
MATH103<br />
MATH101<br />
ENGL100<br />