String.format () - arguments for argumentation

I have a string format String:

String.format("CREATE TABLE %s (" + "%S INTEGER PRIMARY KEY AUTOINCREMENT, %s INTEGER NOT NULL, %s TEXT NOT NULL)", SPORT_TABLE, SPORT_ID, SPORT_WSID, SPORT_TITLE); 

But my second argument ( SPORT_ID ) is capitalized. Why is this happening? What can I do to fix this?

+4
source share
2 answers

it well-documented behavior, even if it is not known (perhaps because it is not an obvious need or something very useful).

From javadoc :

The following table shows supported conversions. The conversions indicated by the uppercase character (that is, "B", "H", "S", "C", "X", "E", "G", "A" and "T") are the same as for the corresponding lower case conversion characters, except that the result is converted to upper case in accordance with the rules of the prevailing Locale. the result is equivalent to the following call to String.toUpperCase ()

+12
source

In your format string, you have %S , and that should be %S Currently, I have not found any documentation on this behavior, but all row selectors ( %S , %f , etc.) should be lowercase.

EDIT: see @dstroy answer for a quote from javadoc.

+8
source

Source: https://habr.com/ru/post/1493515/


All Articles