string-formatting

How to escape curly braces in a format string in Rust

十年热恋 提交于 2019-11-27 07:42:55
问题 I want to write this write!(f, "{ hash:{}, subject: {} }", self.hash, self.subject) But since curly braces have special meaning for formatting it's clear that I can't place the outer curly braces like that without escaping. So I tried to escape them. write!(f, "\{ hash:{}, subject: {} \}", self.hash, self.subject) Rust doesn't like that either. Then I read this: The literal characters {, }, or # may be included in a string by preceding them with the \ character. Since \ is already an escape

String format using MultiBinding?

假如想象 提交于 2019-11-27 07:26:49
I'm trying to display a string in XAML using Label control. Following is my XAML code : <Label Height="28" HorizontalAlignment="Left" Margin="233,68,0,0" Name="label13" VerticalAlignment="Top"> <Label.Content> <MultiBinding StringFormat="{}{0} x {1}"> <Binding Path="Width" /> <Binding Path="Height" /> </MultiBinding> </Label.Content> Width and Height are two properties of my class Movie. I want the label to display : "Width x Height" ex. 800 x 640 However the label control remains empty. Any help is appreciated. I WANT TO DO THIS WITHOUT USING A CONVERTER. I have modified my xaml by using a

Optimal Base-10 only itoa() function? [closed]

故事扮演 提交于 2019-11-27 07:20:41
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . In 20+ years programming in C I've used a base other than 10 once, so when I found my trusty MSVC's _itoa() missing in another environment, I set out to write one that only does base 10, and puts the destination buffer argument, pointing to the storage returned by the

Logger slf4j advantages of formatting with {} instead of string concatenation

爱⌒轻易说出口 提交于 2019-11-27 06:56:36
Is there any advantage of using {} instead of string concatenation? An example from slf4j logger.debug("Temperature set to {}. Old temperature was {}.", t, oldT); instead of logger.debug("Temperature set to"+ t + ". Old temperature was " + oldT); I think it's about speed optimization because parameters evaluation (and string concatenation) could be avoided in runtime depending on a config file. But only two parameters are possible, then sometimes there is no other choice than string concatenation. Needing views on this issue. skaffman It is about string concatenation performance. It's

Chart.js - Formatting Y axis

佐手、 提交于 2019-11-27 06:52:12
I'm using Chart.js to draw a simple bar plot and I need to format its Y axis like 123456.05 to 123 456,05 $ I don't understand how to use scaleLabel : "<%=value%>" I saw someone pointing to " JS Micro-Templating ", but no clue how to use that with our scaleLabel option. Does someone know how to format this Y axis, and maybe give me an example ? Jaison I had the same problem, I think in Chart.js 2.x.x the approach is slightly different like below. ticks: { callback: function(label, index, labels) { return label/1000+'k'; } } More in details var options = { scales: { yAxes: [ { ticks: { callback

python format string unused named arguments [duplicate]

妖精的绣舞 提交于 2019-11-27 06:48:13
This question already has an answer here: partial string formatting 15 answers Let's say I have: action = '{bond}, {james} {bond}'.format(bond='bond', james='james') this wil output: 'bond, james bond' Next we have: action = '{bond}, {james} {bond}'.format(bond='bond') this will output: KeyError: 'james' Is there some workaround to prevent this error to happen, something like: if keyrror: ignore, leave it alone (but do parse others) compare format string with available named arguments, if missing then add If you are using Python 3.2+, use can use str.format_map() . For bond, bond : >>> from

Can maximum number of characters be defined in C# format strings like in C printf?

旧城冷巷雨未停 提交于 2019-11-27 06:38:46
问题 Didn't find how to do that. What I found was more or less on the lines of this (http://blog.stevex.net/string-formatting-in-csharp/): There really isn’t any formatting within a string, beyond it’s alignment. Alignment works for any argument being printed in a String.Format call. Sample Generates String.Format(“->{1,10}<-”, “Hello”); // gives "-> Hello<-" (left padded to 10) String.Format(“->{1,-10}<-”, “Hello”); // gives "->Hello <-" (right padded to 10) 回答1: What you want is not "natively"

Str.format() for Python 2.6 gives error where 2.7 does not

笑着哭i 提交于 2019-11-27 06:38:34
问题 I have some code which works well in Python 2.7. Python 2.7.3 (default, Jan 2 2013, 13:56:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from sys import stdout >>> foo = 'Bar' >>> numb = 10 >>> stdout.write('{} {}\n'.format(numb, foo)) 10 Bar >>> But in 2.6 I get a ValueError exception. Python 2.6.8 (unknown, Jan 26 2013, 14:35:25) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from sys

How to use Python string formatting to convert an integer representing cents to a float representing dollars?

房东的猫 提交于 2019-11-27 06:20:24
问题 I have an integer representing a price in cents. Using Python format strings, how can I convert this value into dollars with two decimal places? Examples: 1234 => 12.34 5 => 0.05 999 => 9.99 EDIT: I should give some background. I am storing prices in a database as integers in order to make sure I don't loose precision. I don't want to use the Decimal datatype because these values will also be used in calculations in Javascript, so integers will be simplest to work with for that. I want to be

Python string formatting: % vs concatenation

最后都变了- 提交于 2019-11-27 05:47:43
问题 I'm developing an application in which I perform some requests to get an object id. After each one of them, I call a method ( get_actor_info() ) passing this id as an argument (see code below). ACTOR_CACHE_KEY_PREFIX = 'actor_' def get_actor_info(actor_id): cache_key = ACTOR_CACHE_KEY_PREFIX + str(actor_id) As can be noticed, I'm casting actor_id to string and concatenating it with a prefix. However, I know I could do it in multiple other ways ( .format() or '%s%d' , for instance) and that