string-formatting

Aligning with string formatting

♀尐吖头ヾ 提交于 2019-12-11 06:44:30
问题 I wish to achieve this sort of output with string formatting: GBP......0.8639......0.8399 I have tried using the following code (i stands for currency and e[0] and e[1] are buy and sell values): "{i:.<10}{e[0]:.^6}{e[1]:.>6}".format(i=i, e=e) but the above code does not align the second number to the right, but it just adds it behind the first number, like this: GBP.......0.86390.8399 How can I correct this? 回答1: As a generalized solution: Use this format string if you want the right column,

String Format Does Not Works For string

会有一股神秘感。 提交于 2019-12-11 06:01:29
问题 I have a serial number which is String type. Like This; String.Format("{0:####-####-####-####}", "1234567891234567" ); I need to see Like This, 1234-5678-9123-4567; Bu this Code does not work? Can you help me? 回答1: That syntax takes an int, try this: String.Format("{0:####-####-####-####}", 1234567891234567); Edit: If you want to use this syntax on a string try this: String.Format("{0:####-####-####-####}", Convert.ToInt64("1234567891234567")) 回答2: For ####-####-####-####, you will need a

String.format for double-width characters

好久不见. 提交于 2019-12-11 05:59:32
问题 Java's String.format does not appear to be aware of double-width characters, such as Japanese or Chinese: System.out.println(String.format("%1$9s: %2$20s : %3$20s\n", "field", "expected", "actual")); System.out.println(String.format("%1$9s: %2$20s : %3$20s\n", "surface", "駆け", "駆け")); The output is not aligned correctly: field: expected : actual surface: 駆け : 駆け Is there a correct way to format double-width characters with String.format ? If not, is there an alternative method or library

scala string formatting with interpolator S not working

蹲街弑〆低调 提交于 2019-12-11 05:57:46
问题 I am new to scala and trying to do some string formatting. val mAPRegisterResponseMessage = s"{\" 'type' \": \"ap_register_response\", \"message_id\": 02,\"register_status\": $registerStatus,\"host_name_type\": $host_name_type, \"host_name\": $host_name, \"port_num\":$port_num }" If I remove the s in the beginning then the string literal is formed but obviously not correctly. However after adding s at the start, I get an error as unclosed character literal for the second backslash. What am I

I don't understand formatting from output of this code

别说谁变了你拦得住时间么 提交于 2019-12-11 05:49:04
问题 As title states, my piece of code which was from an example provided by my professor. My output is: MagazineID Title Publisher Price SubscriptionRate 1 People Times Inc. 4.95 19.95 2 Car and Driver Hachetter Inc. 3.95 19.99 Code: private void btnShowMags_Click(object sender, EventArgs e) { // Creating new instance of the DisplayMags form. DisplayMags displayMags = new DisplayMags(); // find the path where the executable resides string dbPath = Application.StartupPath; // Providing a path to

String format in wpf

。_饼干妹妹 提交于 2019-12-11 05:32:28
问题 I have a TextBox on WPF that is related to the float variable in my model Following the TextxBox: <TextBox Text="{Binding Position, StringFormat=f4}"/> I want that TextBox will display a maximum 4 numbers after the point. So I put StringFormat=f4 . But now, even when I have less than 4 numbers after the point and when I have a whole number it displays with 4 digits after the point. For example, the number 0 is shows that: 0.0000 I want as long as it did not pass the four numbers, display it

MultiBinding StringFormat of TimeSpan

五迷三道 提交于 2019-12-11 05:22:53
问题 I cannot for the life of me get this to work. I need to display hh:mm from a pair of timespan objects in a textblock and it is just not working. This is what I have so far: <TextBlock> <TextBlock.Text> <MultiBinding StringFormat="{}From {0:hh\\:mm} to {1:hh\\:mm}"> <Binding Path="StartTime"/> <Binding Path="EndTime"/> </MultiBinding> </TextBlock.Text> </TextBlock> The text block shows up blank. I've also tried the following with the same results: <TextBlock> <TextBlock.Text> <MultiBinding

Issues with replacing words in a string using a dictionary and the replace() function

半世苍凉 提交于 2019-12-11 05:18:20
问题 Say I have a dictionary, a string and a list of the words in that string. Like this: the_dictionary={'mine': 'yours', 'I': 'you', 'yours': 'mine', 'you': 'I'} the_string='I thought that was yours' list_string=['I','thought','that','was','yours'] This is my code: for word in list_string: if word in the_dictionary: the_string=the_string.replace(word,the_dictionary[word],1) print(the_string) input : I thought that was yours Output : you thought that was mine Here everything works great, but if I

Strip trailing zeroes and decimal point

和自甴很熟 提交于 2019-12-11 03:56:55
问题 With Lua, I'm formatting numbers to a variable number of digits and strip trailing zeroes/decimal points like string.format(" %."..precision.."f", value): gsub("(%..-)0*$", "%1"): gsub("%.$", "") Value is of type number (positive, negative, integer, fractional). So the task is solved, but for aesthetic, educational and performance reasons I'm interested in learning whether there's a more elegant approach - possibly one that only uses one gsub() . %g in string.format() is no option as

How to sort a number with thousands separator

ぐ巨炮叔叔 提交于 2019-12-11 03:31:58
问题 I have tried to sort the number with jQuery Datatables plug-in but is not working with C# string number formats. I have tried: decimal value= 12345678.00 value..ToString("#,##.00"); value.ToString("##,##.##"); value.ToString("0,0.00", CultureInfo.InvariantCulture) but no luck because of the comma. If there is no comma is works fine or all the numbers with same count also working i.e. 01,121,372.01 02,002,009.22 11,222,222,33 If it is as below then it is not working 1,111,111.11 222,191.00 32