0

I have a requirement to concat two string values and these values should be placed between curly braces, I'm trying to define string format as a constant and passing the string values, I have tried many formats but always am getting Invalid Input Parameter exception. Is that possible to do the following using string formatter ? if then how ?

private const string formatString = "'{'{0}'}''{'{1}'}'";

string str1 = "John";
string str2 = "[email protected]";

string resultString = string.Format(formatString, str1, str2);

Expected Output

{John}{[email protected]}

2 Answers 2

5

You must escape it using double curly braces.

private const string formatString = "{{{0}}}{{{1}}}";
Sign up to request clarification or add additional context in comments.

Comments

4

You have to escape { and } in order to use them on string.Format

private const string formatString = "{{{0}}}{{{1}}}";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.