Top "String-formatting" questions

Commonly refers to a number of methods to display an arbitrary number of varied data types into a string.

format strings and named arguments in Python

Case 1: "{arg1} {arg2}".format(10, 20) It will give KeyError: 'arg1' because I didn't pass the named arguments. Case 2: "{arg1} {arg2}".…

python string arguments string-formatting
How to convert a 24 hour time to 12 hour in VB.net as hh:mm AM/PM

So let's say I have 1400, I want to convert it into 2:00PM I tried the following: Dim convertedTime As String = …

vb.net time string-formatting datetime-conversion
How to deal with "%1" in the argument of QString::arg()?

Everybody loves QString("Put something here %1 and here %2") .arg(replacement1) .arg(replacement2); but things get itchy as soon as you …

qt string-formatting placeholder qstring
Reuse a parameter in String.format?

String hello = "Hello"; String.format("%s %s %s %s %s %s", hello, hello, hello, hello, hello, hello); hello hello hello …

java string string-formatting
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'

So I am VERY new to programming and I started with Python 3. I started reading "Learn Python the Hard Way". …

python string-formatting typeerror
How do I format a number with a variable number of digits in Python?

Say I wanted to display the number 123 with a variable number of padded zeroes on the front. For example, if …

python string string-formatting number-formatting
Python TypeError: non-empty format string passed to object.__format__

I hit this TypeError exception recently, which I found very difficult to debug. I eventually reduced it to this small …

python python-3.x string-formatting
String.Format an integer to use a thousands separator without decimal places or leading 0 for small integers

Silly question, I want to format an integer so that it appears with the 1000's separator (,), but also without decimal …

c# string-formatting
How to generically format a boolean to a Yes/No string?

I would like to display Yes/No in different languages according to some boolean variable. Is there a generic way …

c# formatting coding-style string-formatting
Make String.format("%s", arg) display null-valued arguments differently from "null"

Consider the custom toString() implementation of a bean: @Override public String toString() { String.format("this is %s", this.someField); } This …

java string null string-formatting string.format