Why do I get a StringFormat error with this?

c#, string.format, stringbuilder

Solution

You should escape those `{` with double `{{`:

sbJava.Append(string.Format("_{0}.setOnClickListener(new View.OnClickListener() {{ ", btnId));

Problem

With this code (sbJava is a StringBuilder): ``` String androidFindLine = string.Format("Button _{0} = (Button) findViewById(R.id.{0});\"", btnId); sbJava.Append(androidFindLine); sbJava.Append(Environment.NewLine); sbJava.Append(string.Format("_{0}.setOnClickListener(new View.OnClickListener() { ", btnId)); ``` ...I get, System.FormatException was unhandled _HResult=-2146233033 _message=Input string was not in a correct format... The value of btnId is "btnbutton_up" What is the problem?

Original source