We have lots of strings in our resource files that contains format .e.g
“{0} has moved to {1}”
These strings are passed to String.Format() by the applications, sometimes the translators mess up the “formatting markers” Therefore I wish to find/write a tool that checks that all strings in the resource file has a valid format.
I know for each key the numbers of args that are passed to String.Format so that can feed into the validations as well.
So apart from checking that the “{“ match the “}” is there a easy way to find most errors in the format strings?
(I am using .NET, this checking will of course be done as part of the build process)
I have come up with a simple solution that gives a reasonable result, I know the number of argument to the format statement but not the type of the arguments. However most arguments are strings.
So
Of course this would be written without an “if” for each number of arguments in real life.