Getting the number of format specifiers in a string?

When using string.Format (string, object []), it throws an exception if the string contains more format specifiers ({0}, {1: dd-MM-yyyy}, etc.) than the object []. Length.

I would also like to throw an exception if object []. Length contains more specifications. There seems to be no built-in way to do this, so I am trying to get the number of format specifiers in the input string. A complex bit is what {{something}} or {0: dd-MM-yyyy} is allowed to use.

Does anyone know a simple or even built-in way to get the number of format specifiers in a string? I'm currently trying to create a regex, but maybe there is an easier way?

+3
source share
1 answer

It looks like someone has already created a regular expression for this: Is there a better way to count string format placeholders in a string in C #?

+3
source

Source: https://habr.com/ru/post/1717445/


All Articles