string-formatting

Verify if String matches a format String

自闭症网瘾萝莉.ら 提交于 2019-12-12 07:44:54
问题 In Java, how can you determine if a String matches a format string (ie: song%03d.mp3 )? In other words, how would you implement the following function? /** * @return true if formatted equals String.format(format, something), false otherwise. **/ boolean matches(String formatted, String format); Examples: matches("hello world!", "hello %s!"); // true matches("song001.mp3", "song%03d.mp3"); // true matches("potato", "song%03d.mp3"); // false Maybe there's a way to convert a format string into a

Format BigDecimal without scientific notation with full precision

我的未来我决定 提交于 2019-12-12 07:32:14
问题 I'd like to convert a BigDecimal to String for printing purposes but print out all digits without scientific notation. For example: BigDecimal d = BigDecimal.valueOf(12334535345456700.12345634534534578901); String out = d.toString(); // Or perform any formatting that needs to be done System.out.println(out); I'd like to get 12334535345456700.12345634534534578901 printed. Right now I get: 1.23345353454567E+16 . 回答1: To preserve the precision for a BigDecimal you need to pass the value in as a

A fixed number of decimal places with no decimal

牧云@^-^@ 提交于 2019-12-12 06:38:43
问题 I'm trying to mask a decimal value. I would like 19.76 to transform into 1976000 , or even 1976 Another example would be 500.53 would become 50053000 . I would like to do this with the ToString overloads rather than some kind of conversion method as it suits my xml settings file better. I wasnt able to find an IFormatProvider that would not assume a decimal point, I suspect thats what I need however. If I leave out the decimal in the string format like this: ?myvalue 19.76 ?((decimal)myvalue)

SQL Server DataType of TEXT does not maintain formatting

拈花ヽ惹草 提交于 2019-12-12 05:56:50
问题 I have to use a column with a datatype of TEXT in SQL Server 2005 to store a string that I need formatted with newlines and tab character for example. prior to calling the stored proc, I added a breakpoint to view the text I'm sending in the text visualizer in VS2010, and all formatting is exactly how I want it to be, but when I go the the cell in the database, and copy out the data, the formatting is lost. From what I can see, every time it a newline character or tab character is present in

How can I change (i.e. toggle) the bound, StringFormat property of a WPF control?

♀尐吖头ヾ 提交于 2019-12-12 03:07:54
问题 I have a WPF TextBox that has it's text value bound in XAML. This works fine and, as expected, when the associated value is loaded to the field, it is formatted as desired. My issue is when the user enters the text field to modify the value, I want to strip away the formatting, and display the raw underlying value. To do this, I tried to set the BindingExpression.ParentBinding.StringFormat property, on the text boxes binding from within a GotFocus event. However, when I tried to set the

How to do print formatting in Python with chunks of strings?

↘锁芯ラ 提交于 2019-12-12 02:36:36
问题 I'm having some trouble with formatting the pyramid. I've tried to use format when printing from the loop but that didn't seem to work and just breaks the program. What would be different ways to format the output. The only trouble that I am having is when I am printing 10 and up when there's double digits. What would be the best approach formatting the printing output? I've tried variety of ways but couldn't make formatting work within the loop from documentation https://docs.python.org/3.5

How to format date time in language independent way? [duplicate]

情到浓时终转凉″ 提交于 2019-12-12 01:54:09
问题 This question already has answers here : Localized date format in Java (6 answers) Closed 5 years ago . I need to show date and time in this format, Date: 9th Dec, Time: 19:20 Although my following code is working fine in English, have no idea this is correct way in other languages which my application is supporting like Chinese, Thai, etc. Any idea would be appreciated? Thanks This is my code: private String getFormattedTime(Calendar calendar) { int hour = calendar.get(Calendar.HOUR_OF_DAY);

Formatted string literals in Python 3.6 with tuples

旧城冷巷雨未停 提交于 2019-12-12 01:46:47
问题 With str.format() I can use tuples for accesing arguments: >>> '{0}, {1}, {2}'.format('a', 'b', 'c') 'a, b, c' or >>> t = ('a', 'b', 'c') >>> '{0}, {1}, {2}'.format(*t) 'a, b, c' But with the new formatted string literals prefixed with 'f' how can use tuples? 回答1: Your first str.format() call is a regular method call with 3 arguments, there is no tuple involved there . Your second call uses the * splat call syntax; the str.format() call receives 3 separate individual arguments, it doesn't

How to get a formatted std::string in c++ without length liminations

一笑奈何 提交于 2019-12-12 00:12:59
问题 What is the best way (short, using standard libraries and easy to understand) to do this in c++: std::string s = magic_command("%4.2f", 123.456f) without length limitations (char s[1000] = ...) where "%4.2f" is any c format string (which would be given to printf for example) I am aware of the snprintf malloc combo suggested for pure c in writing formatted data of unknown length to a string (C programming) but is there a better, less verbose, way to do this with c++? I am also aware of the std

string.template with arrays as placeholders

﹥>﹥吖頭↗ 提交于 2019-12-11 22:54:06
问题 I have a string that I'm trying to format that looks like this: output = """<div class="form-group" id="$info["id"]_container">""" The formatting call looks like this: Template(output).substitute(locals()) My problem is that the substitution is working, but it's substituting all of the values of the info array instead of the id value that I want. Here's the output: <div class="form-group" id="{'name': 'my_name', 'type': 'my_type', 'label': 'my_label', 'help_text': 'my_help_text', 'id': 'my_id