You need to check the length of the string in
a
before you start using Substring: if it only has three characters for example, you code will fail with the error you are getting.
try this:
if (a == string.Empty)
Becomes
if (string.IsNullOrWhiteSpace(a) || a.Length < 6)