string-formatting

C# String.Format with Curly Bracket in string [duplicate]

泄露秘密 提交于 2019-12-22 01:33:27
问题 This question already has an answer here : Closed 8 years ago . Possible Duplicate: Escape curly brace '{' in String.Format c# has a String.Format method that allows you to format a string but inserting params with the tokens {0} {1} I am trying to create a simple json string which requires curly brackets to be in the string, and so it is breaking the formatter String.Format("{ foo:'{0}', bar:'{1}' }", foo, bar); Adding an escape before the braces did not help Throws a exception saying my

compute age from given birthdate

时光总嘲笑我的痴心妄想 提交于 2019-12-21 20:44:21
问题 I have 2 comboboxes and 2 textboxes. My first combobox contains months in this format january, february, etc, and the other combobox contains numbers from 1 to 31. My first textbox is txtyear . Once the user input birth year to txtyear a variable BOD will be equals to this. Dim BOD as string BOD = cbomonth.text + "-" + cboday.text + "-" + txtyear.text The purpose of my last textbox is to handle the age of the user that will be computed when the cursor lost focus on txtyear . Can anyone help

Python: Print to one line with time delay between prints

这一生的挚爱 提交于 2019-12-21 20:38:58
问题 I want to make (for fun) python print out 'LOADING...' to console. The twist is that I want to print it out letter by letter with sleep time between them of 0.1 seconds (ish). So far I did this: from time import sleep print('L') ; sleep(0.1) print('O') ; sleep(0.1) print('A') ; sleep(0.1) etc... However that prints it to separate lines each. Also I cant just type print('LOADING...') since it will print instantaneously, not letter by letter with sleep(0.1) in between. The example is trivial

StringFormat in XAML, WPF : Currency Formatting

痴心易碎 提交于 2019-12-21 13:32:48
问题 How can i obtain currency formatting according to my country i.e indian rupee, INR or Rs ?? Please tell me the way to achieve this ?? Right now when i use StringFormat="{}{0:C}" , "$" is being used I have gone through this link and i am able to achieve the desired result but i am worried about using this in my project. Is this code safe ?? What does this line mean in the above link "when you test functionality related to settings change it’s important you start the program directly from a

Javascript: why does this produce and ugly string??? I would like currency

江枫思渺然 提交于 2019-12-21 12:33:12
问题 var total = 0; $(".amount").each(function() { var value = $(this).val(); value = (value.length < 1) ? 0 : value; var tmp = parseFloat(value).toFixed(2); total += tmp; }); $(".total").text(total); I am trying to loop through some text boxes and sum up their values. This produces a nasty string. What am I missing?? if I put 8 in the first textbox total text ends up as " 08.000.000.000.00". What am I doing wrong? I would like to format as currency but if not, at least just a two decimal number.

SQL: Binary to IP Address

给你一囗甜甜゛ 提交于 2019-12-21 12:21:39
问题 I'm trying to convert A binary IP to a human-readable IP SELECT HEX( `ip_bin` ) FROM `log_metadata` gives me 4333D26E000000000000000000000000 And SELECT INET_NTOA(0x4333D26E) gives me 67.51.210.110 So I tried: SELECT SUBSTRING( CONVERT(HEX(`ip_bin`), CHAR(32)), 1, 8 ) AS `A` , INET_NTOA( SUBSTRING( CONVERT(HEX(`ip_bin`), CHAR(32)), 1, 8 ) ) AS `B` , INET_NTOA(hex(`ip_bin`)) AS `C` , INET_NTOA(`ip_bin`) AS `D` FROM `log_metadata` But I only get +----------+------------+------------+---------+

Can't use apostrophe in StringFormat of a XAML binding?

假装没事ソ 提交于 2019-12-21 07:26:11
问题 I'm trying use StringFormat to insert apostrophies (apostrophe's?) around a value that is bound to a TextBlock: <TextBlock Text="{Binding MyValue, StringFormat='The value is &apos;{0}&apos;'}"/> However, I get a compile error: Names and Values in a MarkupExtension cannot contain quotes. The MarkupExtension arguments ' MyValue, StringFormat='The value is '{0}''}' are not valid. I do notice that it does work for quotes though: <TextBlock Text="{Binding MyValue, StringFormat='The value is "{0}"'

java String.format: numbers with localization

耗尽温柔 提交于 2019-12-21 07:08:51
问题 Is it possible to localize numbers in String.format call the same way as NumberFormat.format does? I've expected it simply to use String.format(locale, "%d", number) but this doesn't return the same result as if using NumberFormat. For example: String.format(Locale.GERMAN, "%d", 1234567890) gives: "1234567890", while NumberFormat.getNumberInstance(Locale.GERMAN).format(1234567890) gives: "1.234.567.890" If it can't be done, what's recommended way for localizing text including numbers? 回答1:

printf for size_t

自闭症网瘾萝莉.ら 提交于 2019-12-21 07:04:56
问题 Is there any way to give printf a size_t without either casting it first or generating a compiler warning? (I always compile with -Wall .) 回答1: printf("%zu", sizeof(whatever)); 来源: https://stackoverflow.com/questions/4150056/printf-for-size-t

C# How to format a double to one decimal place without rounding

♀尐吖头ヾ 提交于 2019-12-21 06:56:16
问题 I need to format a double value to one decimal place without it rounding. double value = 3.984568438706 string result = ""; What I have tried is: 1) result = value.ToString("##.##", System.Globalization.CultureInfo.InvariantCulture) + "%"; // returns 3.98% 2) result = value.ToString("##.#", System.Globalization.CultureInfo.InvariantCulture) + "%"; // returns 4% 3) result = value.ToString("##.0", System.Globalization.CultureInfo.InvariantCulture) + "%"; // returns 4.0% 4) (Following other