string-formatting

WPF: Textbox Binding with StringFormat={}{0:F2}. Don't show zero's

若如初见. 提交于 2019-12-10 12:39:20
问题 I am binding an object to a TextBox with the following XAML: <TextBox Name="MyTextBox" Text="{Binding Path=MyValue, Mode=TwoWay, StringFormat={}{0:F2}}" /> Naturally when I bind a new object (which values are all still zero) the Text property is set to 0.00 . I have several of these TextBoxes, which makes it tedious to delete every value before entering a new one. At the moment I'm clearing these boxes in the Window_Loaded method using the FindVisualChildren method. It just feels clunky

How to print a list of dicts as an aligned table?

妖精的绣舞 提交于 2019-12-10 11:54:11
问题 So after going through multiple questions regarding the alignment using format specifiers I still can't figure out why the numerical data gets printed to stdout in a wavy fashion. def create_data(soup_object,max_entry=None): max_=max_entry entry=dict() for a in range(1,int(max_)+1): entry[a]={'Key':a, 'Title':soup_object[a].div.text.strip(), 'Link':soup_object[a].div.a['href'], 'Seeds':soup_object[a](attrs={'align':'right'})[0].text.strip(), 'Leechers':soup_object[a](attrs={'align':'right'})

Override date formatting for a culture in .net

牧云@^-^@ 提交于 2019-12-10 11:40:37
问题 We have a problem with the built-in .net date formatting. We are using the abbreviated month format: string.Format("{0:MMM}", date); For our Czech site, it outputs Roman numerals (eg "IV" where in en-GB it would be "Apr"). We want to change this to some custom abbreviations. What is the best way to do this? I don't really want to put an if statement in the view. Should I use a DateTimeFormatInfo? Also, how do Microsoft decide on the formatting, is it based on a standard? 回答1: Which culture do

Best way to achieve complicated numeric formatting in C#

倖福魔咒の 提交于 2019-12-10 10:05:07
问题 What is the best way to replicate the behaviour of something like this in C#? // Converts decimal to a 0-padded string with minimum specified width and precision. sprintf(out, "%0*.*lf", width, precision, decimal); I had a read of standard, custom and composite format strings, but I can't see any nice way to achieve this. The reason I ask is that I just came across this ugly snippet in some code I am maintaining where we are required to format a bunch of decimals according to variable widths

OxyPlot. How to change Format of values next to the axis from 1000 to 1k

我只是一个虾纸丫 提交于 2019-12-10 09:53:12
问题 Im trying to change the format of the value next to the axis from for example 1000 to 1k or 1000000 to 1M. Is this possible in LinearAxis? This is my Code: m.Axes.Add(new LinearAxis { Position = AxisPosition.Right, IsZoomEnabled = false, IsPanEnabled = false, Minimum = -(_maxPointValue2*0.1), Maximum = _maxPointValue2 + (_maxPointValue2*0.1), FontSize = 15, Key = "right", TickStyle = TickStyle.Outside, }); Is this perhaps possible with StringFormat? Also is it possible to change the TickStyle

Date formatting with locale in Play Framework 2.2

亡梦爱人 提交于 2019-12-10 06:48:53
问题 From what I can see in the auto-generated application.conf file, dates/times in Play Framework 2.2 are formatted according to the definition of date.format in that file. I have, for instance, defined date.format=yyyy-MM-dd date.format.dk=d. MMMM yyyy These values, however, seem to be ignored by the framework when printing dates in Scala templates. This thread gives a solution where one enters the pattern directly into the template as myDate.format("yyyy-MM-dd") . (If using Jodatime I guess

Formatting a simple string, but `java.lang.NoSuchMethodError`

怎甘沉沦 提交于 2019-12-10 04:19:38
问题 I'm using Scala 2.9.2. Run Scala and test a simple code, this code is… OK: ... val title = "Hashing file (%s)..." format sizeToStr(file.length) But I couldn't understand what is what, while I put that code into a simple app, compiling OK, at runtime it throws this one: java.lang.NoSuchMethodError: scala.Predef$.augmentString(Ljava/lang/String;)Lscala/collection/immutable/StringOps; at group.pals.penguin.app.shasher.Shasher$.calcHash(shasher.scala:119) at group.pals.penguin.app.shasher.Shasher

python: extracting variables from string templates

大城市里の小女人 提交于 2019-12-10 03:47:07
问题 I am familiar with the ability to insert variables into a string using Templates, like this: Template('value is between $min and $max').substitute(min=5, max=10) What I now want to know is if it is possible to do the reverse. I want to take a string, and extract the values from it using a template, so that I have some data structure (preferably just named variables, but a dict is fine) that contains the extracted values. For example: >>> string = 'value is between 5 and 10' >>> d = Backwards

How to create a variadic template string formatter

别说谁变了你拦得住时间么 提交于 2019-12-10 03:06:58
问题 We need to format strings all the time. It would be so nice to be able to say: std::string formattedStr = format("%s_%06d.dat", "myfile", 18); // myfile_000018.dat Is there a C++ way of doing this? Some alternatives I considered: snprintf : uses raw char buffers. Not nice in modern C++ code. std::stringstream : does not support format pattern strings, instead you must push clumsy iomanip objects into the stream. boost::format : uses an ad-hoc operator overload of % to specify the arguments.

How can I escape '%' character in a gettext string?

╄→尐↘猪︶ㄣ 提交于 2019-12-10 02:04:18
问题 I use gettext to translate my user interface. I'd like to write symbol % as part of a UI caption in a string, but since it has a special meaning, does not works as expected. How can I escape percent symbols? 回答1: Use %% to escape %. 来源: https://stackoverflow.com/questions/3728272/how-can-i-escape-character-in-a-gettext-string