Search code examples
c#stringstring-formattingstringbuilder

String.Format with custom Formatter


I have a custom string formatter, that I want to use after using the Standard formatter, my custom string formatter uses the {0:SP} as its format prefix.

What I am trying to do is get this simple example to work

  String.Format("{{0}:SP}" , 1)

I am getting an exception:

base: {System.FormatException: Input string was not in a correct format.

What it the correct way to do this?


Solution

  • String.Format("{{{0}:SP}}" , 1)
    

    it is annoying but you have to put 2 of them inside if you want to display {1:SP}

    Here is the original answer