I want to add period signs to a initials, and ensure that all letters are capitalized. However, if period signs are already given, than don't add one.
Wanted results:
abc => A.B.C.
Abc => A.B.C.
A.b.c => A.B.C.
Ab.C => A.B.C.
ABC => A.B.C.
A.B.C => A.B.C.
A.B.C.=> A.B.C.
I imagined regex replace would be suitable/optimal for this. So far I could only come up with the following code:
Regex.Replace(initials, @"\w{1}", m => m +".").ToUpper();
This works only in the scenario's when there are no periods in the string, otherwise, it will just add two periods in a row (i.e. a.b.c => a..b..c..)
If other methods than regex replace are more recommended, I warmly welcome them. I work in c#, but wanted to keep the question general to other languages as well.