string.format

String.Format exception when format string contains “{”

送分小仙女□ 提交于 2019-12-28 04:00:27
问题 I am using VSTS 2008 + C# + .Net 2.0. When executing the following statement, there is FormatException thrown from String.Format statement, any ideas what is wrong? Here is where to get the template.html I am using. I want to format this part m={0} in template.html. string template = String.Empty; using (StreamReader textFile = new StreamReader("template.html")) { template = textFile.ReadToEnd(); String.Format(template, "video.wmv"); } http://www.mediafire.com/download.php?u4myvhbmmzg EDIT 1:

How to validate format string

笑着哭i 提交于 2019-12-25 04:30:18
问题 We have lots of strings in our resource files that contains format .e.g “{0} has moved to {1}” These strings are passed to String.Format() by the applications, sometimes the translators mess up the “formatting markers” Therefore I wish to find/write a tool that checks that all strings in the resource file has a valid format. I know for each key the numbers of args that are passed to String.Format so that can feed into the validations as well. So apart from checking that the “{“ match the “}”

C# String.Format() - number format doesn't work

≯℡__Kan透↙ 提交于 2019-12-24 11:28:30
问题 Having tried all different solutions from this question, it doesn't seem to give me the wanted format (1.000.000 | 1.234). I Have tried this: dataBlock.ValueCell.Value = String.Format("{0:#.##0}", double.Parse(dataBlock.ValueCell.Value)); // 1 234 dataBlock.ValueCell.Value = String.Format("{0:N0}", double.Parse(dataBlock.ValueCell.Value)); // 1 234 dataBlock.ValueCell.Value = String.Format("{0}", double.Parse(dataBlock.ValueCell.Value.ToString("N0"))); // 1 234 //values as I read them from

Globalized custom number formatting - Variable decimal points

荒凉一梦 提交于 2019-12-23 20:53:13
问题 I'm trying to alter the existing number formatting in my company's application to make it more readable for international users. This is a stock trading application, so most stock prices come in with numbers precise to 2 decimal points, like so-> 17.23 We could also get ticks in that have precision out to 4 decimal points, so a penny stock might be 0.0341. The original string format that we were using for stocks was "#,##0.00##" Which would give us the format we wanted (essentially trimming

Problem with formatting a string with String.Format in C#

早过忘川 提交于 2019-12-22 11:18:11
问题 I need to print a string in a message box in specific format for which i am using code similar to as shown below: string text=""; for (int i=0; i<n; i++) { a=.. b=.. c=.. text += String.Format("{0, -8} {1,-4} {2,8}", a, b, c); } MessageBox.Show(text); So for following set of values: XYZ,ABC,100 X,ABC,100 I get following output: XYZ ABC 100 X ABC 100 So you can see the second line is not well formatted. Probably this is happening because i am printing this in MessageBox. The space a character

String.Format for currency on a TextBoxFor

青春壹個敷衍的年華 提交于 2019-12-22 01:27:23
问题 I am trying to get @String.Format("{0:0.00}",Model.CurrentBalance) into this @Html.TextBoxFor(model => model.CurrentBalance, new { @class = "required numeric", id = "CurrentBalance" }) I just want the currency to show up as .00 inside of my textbox but am having no luck. Any ideas on how I do this? 回答1: string.format("{0:c}", Model.CurrentBalance) should give you currency formatting. OR @Html.TextBoxFor(model => model.CurrentBalance, new { @class = "required numeric", id = "CurrentBalance",

String.Format for C++

蓝咒 提交于 2019-12-20 08:49:00
问题 Looking for an implementation for C++ of a function like .NET's String.Format. Obviously there is printf and it's varieties, but I'm looking for something that is positional as in: String.Format("Hi there {0}. You are {1} years old. How does it feel to be {1}?", name, age); This is needed because we're going to try and make it easier to localize our app, and giving the translators {0} and {1} to position anywhere in the sentence is much easier than giving them a %s, %d, %d which must be

Odd System.Format Exception [duplicate]

╄→гoц情女王★ 提交于 2019-12-19 09:41:33
问题 This question already has answers here : String.Format exception when format string contains “{” (5 answers) Closed 4 years ago . I am just trying to build a json string for my unit test and unexpectedly the following code returns system format exception. The error message indicates that it is trying to parse date which is quite odd to me. I am not asking to parse date. class Program { static void Main(string[] args) { Console.WriteLine(GetJson()); Console.ReadKey(); } static string GetJson

Can I format NULL values in string.Format?

人盡茶涼 提交于 2019-12-18 13:54:10
问题 I was wondering if there's a syntax for formatting NULL values in string.Format, such as what Excel uses For example, using Excel I could specify a format value of {0:#,000.00;-#,000.00,NULL} , which means display the numeric value as number format if positive, number format in parenthesis if negative, or NULL if the value is null string.Format("${0:#,000.00;(#,000.00);NULL}", someNumericValue); Edit I'm looking for formatting NULL / Nothing values for all data types, not just numeric ones.

java equivalent to printf(“%*.*f”)

陌路散爱 提交于 2019-12-18 05:43:32
问题 In C, the printf() statement allows the precision lengths to be supplied in the parameter list. printf("%*.*f", 7, 3, floatValue); where the asterisks are replaced with first and second values, respectively. I am looking for an equivalent in Android/Java; String.format() throws an exception. EDIT: Thanks, @Tenner; it indeed works. 回答1: I use int places = 7; int decimals = 3; String.format("%" + places + "." + decimals + "f", floatValue); A little ugly (and string concatenation makes it not