string-formatting

Printing Null Character (“\x00”) in Python vs C

女生的网名这么多〃 提交于 2019-12-20 03:33:15
问题 When I code and run the statement: print "\x00\x00\x00" in Python it outputs three blank spaces followed by a newline. But in C, when I code and run the statement: char hex[] = "\x00\x00\x00"; printf("%s\n", hex); it interprets the NULL bytes like I thought it would: it doesn't do anything. So why in Python are NULL bytes treated as spaces?... 回答1: So why in Python are NULL bytes treated as spaces? It's not. Your terminal/console is treating them like spaces. C just happens to stop at the

Print big number in hexadecimal

社会主义新天地 提交于 2019-12-20 03:03:58
问题 I'm trying to convert big number to hexadecimal representation in R, but it fails, because it can't fit into 32-bit integer. Is there any way to overcome this limitation? > print(0xffffffff+0x10000000) [1] 4563402751 > as.hexmode(0xffffffff+0x10000000) Error in if (is.double(x) && (x == as.integer(x))) x <- as.integer(x) : missing value where TRUE/FALSE needed In addition: Warning message: In as.hexmode(4294967295 + 268435456) : NAs introduced by coercion 回答1: Luckily I found the solution,

In Python 2, can I pass a list to the percent-format operator?

血红的双手。 提交于 2019-12-20 02:49:35
问题 I have a list of things I'd like to print using a format string. In Python 3-style, using "a string".format(arg,arg,arg) , this is easy. I can just replace with arguments with *mylist , like mylist = [1,2,3] "{} {} {}".format(*mylist) I can't seem to make this work with the older percent-formatting. I've tried stuff like "%i %i %i" % mylist , %i %i %i" % (mylist) , and %i %i %i" % (*mylist) but I just keep getting syntax errors or "not enough arguments". Is this impossible in 2.x style? ETA:

VB6 Format function: analog in .NET

て烟熏妆下的殇ゞ 提交于 2019-12-19 21:54:31
问题 There is String.Format function that is referred to in the documentation as the analog for Format function from VB6. There's also Format function from VisualBasic namespace that is provided for compatibility and basically has same powers as String.Format . Indeed, those two format dates and numbers. But VB6's function was also able to format strings: ? format$("hi there", ">") HI THERE ? format$("hI tHeRe", "<") hi there ? format$("hi there", ">!@@@... not @@@@@") HI ... not THERE String

VB6 Format function: analog in .NET

安稳与你 提交于 2019-12-19 21:54:04
问题 There is String.Format function that is referred to in the documentation as the analog for Format function from VB6. There's also Format function from VisualBasic namespace that is provided for compatibility and basically has same powers as String.Format . Indeed, those two format dates and numbers. But VB6's function was also able to format strings: ? format$("hi there", ">") HI THERE ? format$("hI tHeRe", "<") hi there ? format$("hi there", ">!@@@... not @@@@@") HI ... not THERE String

Format a number to always have a sign and decimal separator [duplicate]

喜欢而已 提交于 2019-12-19 19:53:43
问题 This question already has answers here : Custom numeric format string to always display the sign (6 answers) Closed 5 years ago . I want to format any number (integer or real) to a string representation which always has a sign (positive or negative) and a decimal separator , but no trailing zeroes. Some samples: 3.14 => +3.14 12.00 => +12. -78.4 => -78.4 -3.00 => -3. Is it possible with one of the default ToString() implementations, or do I need write this myself? 回答1: Try something like this

Format a subset of text in Excel Cell Using Formula

ε祈祈猫儿з 提交于 2019-12-19 17:14:43
问题 I Have built a string using a formula in excel. as an example Cell C3 contains text "Languages" Cell C4 = "English, Spanish,German, French" My Forumla = C3 & ":" & CHAR(10) & C4 The Desired text would be: Languages: English, Spanish, German, French (where the bold text would actually be some color like red) Is there a way to do this in Excel (change partial text formatting) . I Have tried a formula... (Not working) Function formatText(InText As Range) 'Set font color InText.Characters(1.5)

how format specifier taking value while tuple list is passed

╄→гoц情女王★ 提交于 2019-12-19 11:54:41
问题 I have a piece of code as below: tupvalue = [('html', 96), ('css', 115), ('map', 82)] So while printing the above tuple in the desired format for a particular index I found a code like this: >>> '%s:%d' % tupvalue[0] 'html:96' I'm wondering how the single value tupvalue[0] is recognised as a tuple of two values by the format specifier '%s:%d' ? Please explain this mechanism with a documentation reference. How can I use a comprehension to format all the values in tupvalue in the required

String.format() throws FormatFlagsConversionMismatchException

一个人想着一个人 提交于 2019-12-19 07:28:10
问题 This code works fine in Java 1.6: public static String padLeft(String s, int n) { if (n <= 0) return s; int noOfSpaces = n * 2; String output; noOfSpaces = s.length() + noOfSpaces; output = String.format("%1$#" + noOfSpaces + "s", s); return output; } But newer versions (and some other VM implementations) throw this Exception : java.util.FormatFlagsConversionMismatchException: Mismatched Convertor =s, Flags= # at java.util.Formatter$Transformer.transformFromString(Formatter.java:1020) at java

Padding number with leading zeros in XSLT 1.0

扶醉桌前 提交于 2019-12-19 06:39:09
问题 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