What do "% s", "% d", etc. mean? In Delphi programming?

Every time I look at some more expert code online, I see things like %s and %d on some lines, especially in dialogs, but I have no idea what it is. I have googled terms, and I can not find the answer and whether it is Delphi-bound or something common for each programming language.

I saw a message related to C saying that it is used to "convert variables at run time", how many arguments can we specify on one line, if so?

Usage example:

 ShowMessageFmt('Day %d = %s',[i,Days[i]]); 

found in Delphi Basics .

+8
delphi
source share
2 answers

These are format strings similar to those used in C printf() . They are also used by the Delphi Format function, which again resembles printf() in C.

%d is an integer. It will be replaced by the contents of the variable i , which is provided in the next array.

%s represents a string. It will be replaced by the contents of Days[i] , which is passed in the array that follows it.

You can find more information in the Delphi documentation for SysUtils.Format , in particular in the Format Strings subsection.

+21
source share

These are format strings that are passed to the Format function. Read all about this in the documentation .

Each placeholder in your format string is replaced with the value from the open array argument. So, %d is replaced by the value of i , and %s is replaced by the value of Days[i] .

Format string placeholders specify the data type and formatting information. Thus, %d used to display an integer value in decimal, and %s used to indicate a string.

+12
source share

All Articles