I completely understand your logic. I was telling you how to interpret my pseudo-code so you could turn it into actual code.
Here's a list of built-in functions you can use within your custom function to generate the results you want:
I know you are going to need Mid(). Possibly Replace(), UCase() and InStr as well.