Home:ALL Converter>What is C# analog of C snprintf()?

What is C# analog of C snprintf()?

Ask Time:2010-07-25T07:30:24         Author:Rella

Json Formatter

What is C# analog of C snprintf()?

In C code here we use

 snprintf(buf, sizeof(buf), outfilename, frame);

What could be its exact analog?

Author:Rella,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/3327327/what-is-c-sharp-analog-of-c-snprintf
Sam Harwell :

StringBuilder.AppendFormat String.Format is the closest. It performs the same operation, but do note that the format strings are in a different format.\n\nUsing String.Format:\n\nstring buf = string.Format(\"{0}\", frame);\n\n\nUsing StringBuilder.AppendFormat:\n\nStringBuilder builder = new StringBuilder();\nbuilder.AppendFormat(\"{0}\", frame);\n",
2010-07-24T23:32:03
Mark Byers :

The most basic version is String.Format.\n\nstring result = String.Format(format, arg0, arg1, ..., argn);\n\n\nBut many other classes support something similar, including all classes that derive from TextWriter. There are some examples in this question Which methods in the 3.5 framework have a String.Format-like signature?\n\n\nConsole.Write\nStreamWriter.Write\nStringWriter.Write\nStringBuilder.AppendFormat\nmany more...\n",
2010-07-24T23:37:53
Bob G :

If you're assigning to a string, use String.Format\n\nvar newString = String.Format(\"Number: {0}\", 10);\n\n\nIf you're looking to append a ton of strings, use the StringBuilder.AppendFormat. It'll save you in the long run because they can be chained, saving space.\n\nvar result = new StringBuilder().AppendFormat(\"{0}\", 10).AppendFormat(\"{0}\", 11).ToString();\n",
2010-07-24T23:44:08
yy