Related Tags:
Asp.Net It was developed by Microsoft to allow programmers to build dynamic web sites, web applications and web services. It was first released in January 2002 with version 1.0 of the .NET Framework, and is the successor to Microsoft's Active Server Pages (ASP) technology. Learn More, C# C# (pronounced "C-sharp") is an object-oriented programming language from Microsoft that aims to combine the computing power of C++ with the programming ease of Visual Basic. C# is based on C++ and contains features similar to those of Java. Learn More, ASP.NET MVC The ASP.NET MVC framework is a lightweight, highly testable presentation framework that (as with Web Forms-based applications) is integrated with existing ASP.NET features, such as master pages and membership-based authentication. The MVC framework is defined in the System.Web.Mvc assembly. Learn More,

string.Format in C# always returning error 'Input string was not in a correct format.'

Description:I have to format following string as mention in the following code.

string.Format("gtag('event', 'conversion', {'send_to': '{0}/{1}'});", "aw-xxxx", "xxxx");

But it always throwing error 'Input string was not in a correct format.' Needs to know what is wrong in the above code.

Posted by: | Posted on: May 10, 2018

1 answers



It is not working because anything written within curly braces String.Format considers it as argument. So you should use double curly braces like {{ or }} so your code become

New Code
string.Format("gtag('event', 'conversion', {{'send_to': '{0}/{1}'}});", "aw-xxxx", "xxxx");

Your Previous Code

string.Format("gtag('event', 'conversion', {'send_to': '{0}/{1}'});", "aw-xxxx", "xxxx");

Cheers !

Replied by: | Replied on: May 11, 2018