1

I have run into the use of {0} in the App.config of a project I'm working on and I can't find anything on how it works. The only other question on it I found is the this question which explains how composite formatting works but nothing about its use in the .config file

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
    <appSettings>
      <add key="UriUpdateProfile" value="{0}/profiles/{1}" />
      ...
    </appSettings>
  </configuration>
  • 3
    Please include the C# code that reads the `UriUpdateProfile` entry from config. I'd bet my money that you are running `string.Format` on it. – mjwills Jul 06 '17 at 22:00
  • I wasn't able to find it but now that I've done more research I'm willing to bet the same – user3220670 Jul 06 '17 at 22:14

2 Answers2

2

It doesn't mean anything in the config file. In the code, this literal string "{0}/profiles/{1}" will be acquired from the configuration. This string will then be used in a composite formatting function such as String.Format or Console.WriteLine. In the code, where those functions are called, you'll find the arguments that fill in the "{0}" and "{1}" placeholders.

Michael Gunter
  • 12,528
  • 1
  • 24
  • 58
0

For hard-coded strings that depend on user data, these sorts of configurations play very well with format strings. Your example configuration would be read and updated with

String.Format(uriUpdateProfile, variable0, variable1);

String.Format takes a large number of variables and repacles {0} and {1} with the passed in arguments. There are other ways to replicate this, and even simple replacements such as String.Replace("{0}", userID); could suffice.

dckuehn
  • 2,427
  • 3
  • 27
  • 37