String already contains {} and using place holders

Hi Team

For sending email I am using the IsBodyHtml attribute. In the html text I am replacing variables with place holders like {0} {1}. But the html file already contains some data inside {} as style. So when I am using String.Format method its throwing error.

So how to handle that part coming under {} as I am also using place holders as {0}, {1} etc.

You might try using this as a base template example.

String.Format("Hello! My name is {0} {1}, and I am {2} years old.", "John", "Doe", 18.ToString).

Why don’t you directly insert variables in HTML Body?
if yes then try inserting like this “string”+variable+“string”
Happy Automation!

Hi @kkpatel,

You can have your style in separate variable and body in a separate variable. Use the String.Format in the second variable. and append it to first variable.

Warm Regards,
Ranjith Udayakumar

@kkpatel Replace style parenthesis {} with double parenthesis {{}} in your html. It will resolve your issue.

I have an html file. In that file I have replaced all the variable part with place holders. Then I am reading the whole text from that file and storing in a string variable. Then using String.Format method passing the string variable and giving the values. But in that text itself already {} is used in html style which is throwing error as incorrect format exception.

If the string already contains { or }, you would need to use something else. It’s cumbersome, but you could use different delimiters and the Replace function. For instance, if MyString = "Hello! My name is ~0~ ~1~, and I am ~2~ years old.":

MyString.Replace("~0~", "John").Replace("~1~", "Doe").Replace("~2~", 18.ToString)

1 Like

Yes can be done.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.