Question

I have the following string

"ListId={1CC88B01-E60F-45D1-8B3C-28852574156D}&ID={0}&ContentTypeID=0x01003D458D19EF31D845B3A7727B0F2F8FC8"

I would like to use it as such

String.Format("ListId={1CC88B01-E60F-45D1-8B3C-28852574156D}&ID={0}&ContentTypeID=0x01003D458D19EF31D845B3A7727B0F2F8FC8", MyValue)

WHERE MyValue would replace ID={0}

However this throws a System.FormatException. Obviously this is because of the {1CC88B01-E60F-45D1-8B3C-28852574156D} guid that uses the string.format placeholder value. Now I can simply split the string call string.format() as required and concat it back together but is there perhaps some way I can avoid doing that by "escaping" the placeholder value somehow?

Was it helpful?

Solution

You just need to double the braces:

String.Format("ListId={{1CC8...156D}}&ID={0}&...", MyValue)

OTHER TIPS

Use double {{ or }} characters to escape them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top