I am replacing some very old c++ code that is in use at my job with a c# desktop app. In the c++ a naming convention was established that included smartcoding (yes, bad, I know but I can't change it) in some persisted object names. In the old code, if a name string begins with a number, the named object is handled with a distinct type of object (0-9 only, no other possibilities such as the Persian digits, & etc. referenced here: Is \d less efficient than [0-9]). I know there are dozens of ways to determine this and I only have to test the first character but I'm curious what's my better choice between something like this
Regex reg = new Regex("[0-9]");
bool bdistinct = reg.IsMatch(objname.Substring(0,1));
and something like this
char k0 = objname.ToCharArray(0,1)[0];
bool bdistinct = ((k0>='0')&&(k0<='9'));
or is there something else obvious and far simpler that I'm not considering?
I don't know if it makes any difference (and I guess that is an underlying question) but I don't use any RegEx references anywhere else in the replacement code (so far) which is all pretty simple stuff (very few namespaces and references in use).