string.format

Using String.Format To Dynamically Provide The Max Amount of Padding Needed

大憨熊 提交于 2019-12-11 13:44:58
问题 Hello I am trying to make my Console Application assignment more aesthically pleasing and by doing this I have decided to implement String.Format into my loops. We haven't been taught it but it is pretty easy to pick up. The main problem here is how do I parse a int into the String.Format so that it provides the max space needed. This is the loop: for (int index = 0; index < files.Length; index++) { int maxNumericalSize = 2; int fileNumberSystem = index + 1; string result = string.Format("{0

Setter of property bound to Entry.Text loops infinitely

倾然丶 夕夏残阳落幕 提交于 2019-12-11 12:42:38
问题 This is driving me crazy. I have been looking for the source of the issue for hours, but i am starting to suspect this is not an issue in my logic... Maybe i am wrong. Issue description I have a simple Entry . Its Text property is bound to a property with type double in a ViewModel . At the same time i subscribe to the Unfocused Event whose EventHandler simply sets the entry.Text property to "1.0" (actually i can reproduce the issue for x.y0, that is any decimal whose final digit is 0). If

String.Format is misaligned horribly for some reason

匆匆过客 提交于 2019-12-11 07:42:53
问题 I'm used to using printf, but my research led me to believe I could use String.Format for setting up tables in a JTextArea and that it was essentially the same thing. This is for a rhythm game app. My code is: private final String HEADER = "%-10s%-15s%-90s%-9s%-6s%-9s%-7s%-6s%-9s"; ... ranks.setText(""); ranks.append(String.format(HEADER + "\n", "Rank", "Difficulty", "Song Name", "Perfects", "Goods", "Averages", "Misses", "Boos", "MaxCombo")); ranks.append(analyze.toString()); ... return

Is the time format in 24-hour format?

巧了我就是萌 提交于 2019-12-11 06:27:41
问题 I get a time format string passed to me in a string. It could be a standard string like "t", but could be a custom one (containing "HH", etc). How can I find out, that if displayed it'll be a 12-hour or 24-hour format ? (depending on culture and everything...) 回答1: The easiest way is to try a date that you can then examine for a given number in the string, that you'd only expect that way. E.g. whether 2000-01-01T19:00:00Z resulted in a string containing a 7 or a 9 or both. To be certain in

format string- compile time checking

血红的双手。 提交于 2019-12-11 03:22:55
问题 Is there any way to check the format string at compile time ? Example: Console.WriteLine("{0} is a really {1} site", "stackoverflow.com", "cool");//this will run //this will give an exception as only one argument is supplied Console.WriteLine("{0} is a really {1} site", "stackoverflow.com"); Exception:"Index (zero based) must be greater than or equal to zero and less than the size of the argument list." and if format string is not in the correct format (i.e. missing the "}" after 1 here )

How does an asterisk `*` work in the string formatting method `.format(*) ` in Python 3?

天涯浪子 提交于 2019-12-11 03:19:21
问题 What is the use of * in .format(*) ? When using it in the format function below print(new_string.format(*sum_string)) it changes the value of sum_string in the output from 18 to 1 Why does that happen? I have read the following link about *args and **kwargs but couldn't understand how does that apply to the .format() function What does ** (double star/asterisk) and * (star/asterisk) do for parameters? sum_string = "18" new_string = "This is a new string of value {}" print(new_string.format

Converting Number to Comma Separated Values

本小妞迷上赌 提交于 2019-12-11 01:56:02
问题 I Need to convert numbers in comma separated format to display in C# . For Example: 1000 to 1,000 45000 to 45,000 150000 to 1,50,000 21545000 to 2,15,45,000 How to achieve this in C# ? I tried the below code: int number = 1000; number.ToString("#,##0"); But it is not working for lakhs . 回答1: I guess you can do this by creating a custom number format info for your needs NumberFormatInfo nfo = new NumberFormatInfo(); nfo.CurrencyGroupSeparator = ","; // you are interested in this part of

How to apply different formatting depending on whether number is positive or negative

心已入冬 提交于 2019-12-10 18:19:06
问题 I'm outputting a Double that can be either (+) or negative (-). If the number is a negative the symbol (-) is included automatically, is there a way to do this for positive numbers as well? The only (horrible) way I can do this is : If MyNumber <= 0 then string.Format("{0:0.00}", MyNumber) Else string.Format("+{0:0.00}", MyNumber) End If 回答1: You can use the section separator in your format: string.Format("{0:+0.00;-0.00}", num); The format before the semi-colon will be used for positive

String.Format or Not? [duplicate]

我只是一个虾纸丫 提交于 2019-12-10 04:35:48
问题 This question already has answers here : Closed 11 years ago . Duplicate from : String output: format or concat in C#? Especially in C# world using String.Format for everything is really common, normally as VB.NET developer unless I have to* I don't String.Format, I prefer normal string concatenation, such as: V1 = V2 & "test-x" & V3 & "-;" to me it's better than this: V1 = String.Format("{0} test-x {1} -;", V2, V3) Am I missing something? Or is this just a personal preference? Reasons to Use

String.Format: Input string was not in a correct format [closed]

依然范特西╮ 提交于 2019-12-09 07:28:43
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . The following code keep giving me error saying Input string was not in a correct format, but I am pretty sure it is right, isn't it? int id = 112; String