string-formatting

Concatenate int and string

假如想象 提交于 2019-12-17 16:53:34
问题 How can I concatenate an int (e.g: 4 ) and a string (e.g: @"/12" ) for printing? I'm okay with casting the int it to an NSString format, but I don't know how I can add @"/12" after the int's value. 回答1: I don't get your question, but I think you mean something like this: ...[NSString stringWithFormat:@"%d/12", intValue] 来源: https://stackoverflow.com/questions/5884367/concatenate-int-and-string

How to create a NSString from a format string like @“xxx=%@, yyy=%@” and a NSArray of objects?

谁都会走 提交于 2019-12-17 15:42:13
问题 Is there any way to create a new NSString from a format string like @"xxx=%@, yyy=%@" and a NSArray of objects? In the NSSTring class there are many methods like: - (id)initWithFormat:(NSString *)format arguments:(va_list)argList - (id)initWithFormat:(NSString *)format locale:(id)locale arguments:(va_list)argList + (id)stringWithFormat:(NSString *)format, ... but non of them takes a NSArray as an argument, and I cannot find a way to create a va_list from a NSArray... 回答1: It is actually not

How do I customize output of a custom type using printf?

我们两清 提交于 2019-12-17 11:23:12
问题 I've read through a good chunk of Expert F# and am working on building an actual application. While debugging, I've grown accustomed to passing fsi commands like this to make things legible in the repl window: fsi.AddPrinter(fun (x : myType) -> myType.ToString()) I would like to extend this to work with the printf formatter, so I could type e.g. printf "%A" instanceOfMyType and control the output for a custom type. The book implies that this can be done (p 93, "Generic structural formatting

Why does C's printf format string have both %c and %s?

谁都会走 提交于 2019-12-17 10:25:39
问题 Why does C's printf format string have both %c and %s ? I know that %c represents a single character and %s represents a null-terminated string of characters, but wouldn't the string representation alone be enough? 回答1: Probably to distinguish between null terminated string and a character. If they just had %s , then every single character must also be null terminated. char c = 'a'; In the above case, c must be null terminated. This is my assumption though :) 回答2: %s prints out chars until it

String format using MultiBinding?

China☆狼群 提交于 2019-12-17 09:22:07
问题 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

String format using MultiBinding?

亡梦爱人 提交于 2019-12-17 09:21:58
问题 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

Chart.js - Formatting Y axis

社会主义新天地 提交于 2019-12-17 08:31:18
问题 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 ? 回答1: 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)

Display Float as String with at Least 1 Decimal Place

。_饼干妹妹 提交于 2019-12-17 07:47:10
问题 I want to display a float as a string while making sure to display at least one decimal place. If there are more decimals I would like those displayed. For example: 1 should be displayed as 1.0 1.2345 should display as 1.2345 Can someone help me with the format string? 回答1: Use ToString(".0###########") with as much # as decimals you want. 回答2: This solution is similar to what other are saying, but I prefer to use string.Format. For example: float myFloat1 = 1.4646573654; float myFloat2 = 5;

How to format TimeSpan in XAML

♀尐吖头ヾ 提交于 2019-12-17 07:15:34
问题 I am trying to format a textblock which is bound to a TimeSpan property. It works if the property is of type DateTime but it fails if it is a TimeSpan . I can get it done using a converter. But I am trying to find out if there is any alternatives. Sample Code: public TimeSpan MyTime { get; set; } public Window2() { InitializeComponent(); MyTime = DateTime.Now.TimeOfDay; DataContext = this; } Xaml <TextBlock Text="{Binding MyTime,StringFormat=HH:mm}"/> I am expecting the textblock to show only

VBScript: What is the simplest way to format a string?

陌路散爱 提交于 2019-12-17 06:54:31
问题 I have the following format: Value1 is {0} and Value2 is {1}. I need to replace the numbers in the brackets with strings. This is easily done in most languages using string.Format or something along those lines. How can I do this using only vbscript? I've tried: Replace (strFormat, "{0}", value1) Replace (strFormat, "{1}", value2) It does not work. Any solutions? 回答1: Replace (strFormat, "{0}", value1) Based on your code snip, I'm guessing you believe Replace mutates strFormat directly. It