string-formatting

Padding number with leading zeros in XSLT 1.0

我是研究僧i 提交于 2019-12-19 06:38:12
问题 We have a number in XML that can go up to 3 digits in a large XML file that has to be converted to fixed length text for loading into another system. I need to pad this with leading zeros to a length of 15 in the output (which is fixed length text) Examples: - 1 becomes 000000000000001 - 11 becomes 000000000000011 - 250 becomes 000000000000250 I tried this: <xsl:value-of select="substring(concat('000000000000000', msg:BankAccount/msg:Counter), 12, 15)"/> to get the 15 zeros at the beginning

PHP money_format

馋奶兔 提交于 2019-12-19 05:47:44
问题 I'm using on money_format with the first parameter being '%n' to include the dollar sign, and I have the locale set to en_US but it still doesn't include it. Why? 回答1: From the PHP.net comment: If money_format doesn't seem to be working properly, make sure you are defining a valid locale. For example, on Debian, 'en_US' is not a valid locale - you need 'en_US.UTF-8' or 'en_US.ISO-8559-1'. This was frustrating me for a while. Debian has a list of valid locales at /usr/share/i18n/SUPPORTED;

Lisp string formatting with named parameters

喜欢而已 提交于 2019-12-19 05:17:35
问题 Is there a way in Lisp to format a string using named parameters? Perhaps something with association lists like (format t "All for ~(who)a and ~(who)a for all!~%" ((who . "one"))) in order to print "All for one and one for all" . Similar to this python question, or this scala one, or even c++, but in Lisp. If this functionality isn't in the language, does anyone have any cool functions or macros that could accomplish the same thing? 回答1: Use CL-INTERPOL. (cl-interpol:enable-interpol-syntax)

Using an array as argument for string.Format()

好久不见. 提交于 2019-12-19 05:11:24
问题 When trying to use an array as an argument for the string.Format() method, I get the following error: FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. The code is as follows: place = new int[] { 1, 2, 3, 4}; infoText.text = string.Format("Player1: {0} \n Player2: {1} \n Player3: {2} \n Player4: {3}", place); The Array contains four values and the arguments in the String.Format() are also the same. What causes this error?

Why can't I correctly parse this date string with NSDateFormatter?

社会主义新天地 提交于 2019-12-19 04:22:32
问题 I'm trying to parse a string that was generated by an NSDateFormatter using another NSDateFormatter with the same format. Rather than trying to make that previous sentence make sense, here's some code: NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"MMM dd, YYYY HH:mm"]; NSDate *now = [[NSDate alloc] init]; NSString *dateString = [format stringFromDate:now]; NSDateFormatter *inFormat = [[NSDateFormatter alloc] init]; [inFormat setDateFormat:@"MMM dd, YYYY HH

Format: add trailing spaces to character output to left-justify

你。 提交于 2019-12-19 04:15:09
问题 How do you format a string to have constant width and be left-justified? There is the Aw formatter, where w denotes desired width of character output, but it prepends the spaces if w > len(characters) , instead of appending them. When I try 44 format(A15) print 44, 'Hi Stack Overflow' I get > Hi Stack Overflow< instead of >Hi Stack Overflow < Is there any simple Fortran formatting solution that solves this? 回答1: As noted in the question, the problem is that when a character expression of

Format: add trailing spaces to character output to left-justify

六月ゝ 毕业季﹏ 提交于 2019-12-19 04:15:07
问题 How do you format a string to have constant width and be left-justified? There is the Aw formatter, where w denotes desired width of character output, but it prepends the spaces if w > len(characters) , instead of appending them. When I try 44 format(A15) print 44, 'Hi Stack Overflow' I get > Hi Stack Overflow< instead of >Hi Stack Overflow < Is there any simple Fortran formatting solution that solves this? 回答1: As noted in the question, the problem is that when a character expression of

Python display milliseconds in formatted string using `time.strftime`

可紊 提交于 2019-12-19 03:21:54
问题 I am trying to format milliseconds to formatted string preserving the milliseconds part. Here's my code: import time time.strftime('%Y-%m-%d %H:%M:%S:%f', time.gmtime(1515694048121/1000.0)) where 1515694048121 is a time in milliseconds . It returns me: 2018-01-11 18:07:28:f As we can see, the millisecond portion of time is not returned. What is correct format to include millisecond portion of time? Is '%Y-%m-%d %H:%M:%S:%f' not correct ? 回答1: There is the no directive mentioned in time

Get keys from template

佐手、 提交于 2019-12-18 19:07:27
问题 I would like to get a list of all possible keyword arguments a string template might use in a substitution. Is there a way to do this other than re? I want to do something like this: text="$one is a $lonely $number." keys = get_keys(text) # keys = ('one', 'lonely', 'number') I'm writing a simple Mad-lib-like program, and I want to perform template substitution with either string.format or Template strings. I'd like to write the 'story' and have my program produce a template file of all the

NumberFormat text field without commas

大城市里の小女人 提交于 2019-12-18 15:54:33
问题 I have a JFormattedTextField which I want to accept numbers in the 5 digit range. The following code works correctly: myNumberBox = new JFormattedTextField(NumberFormat.getIntegerInstance()); However, when I type "12345" into the field and switch focus, a comma is inserted due to my locale, making the text "12,345". How can I prevent commas from being added to my input? Better yet, can they be stripped out even if the user does insert commas? 回答1: You have to disable the grouping in your