Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

delphi

Everytime I look at some of the more expert code online I see things like %s and %d in some strings, especially in dialogs, but I have no idea what they are. I have googled the terms and I can't seem to find the answer and whether it is Delphi-bound or something common to every programming language.

I saw a post relating to C saying that it is used to "convert variables at runtime", how many arguments can we specify in a single string if this is the case?

Example usage:

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

found at Delphi Basics.

like image 889
Jacques Koekemoer Avatar asked Sep 04 '13 11:09

Jacques Koekemoer


People also ask

What is %- 8d in C?

Minimum Field Width Specifier In the above program, %8d specifier displays the value after 8 spaces while %-8d specifier will make a value left-aligned.

What is format in Delphi?

Description. The Format function provides 'C' like formatting of multiple of simple data types into a string. It provides very precise control over this formatting. The Formatting parameter defines how the Data array is manipulated into the returned string.

What does %d do in Python?

The %d operator is used as a placeholder to specify integer values, decimals, or numbers. It allows us to print numbers within strings or other values. The %d operator is put where the integer is to be specified. Floating-point numbers are converted automatically to decimal values.

What does %5d mean in Java?

"%5d" Format a string with the required number of integers and also pad with spaces to the left side if integers are not adequate. "%05d" Format a string with the required number of integers and also pad with zeroes to the left if integers are not adequate.


2 Answers

Those are format strings, similar to those used in C printf(). They're also used by the Delphi Format function, which again is similar to printf() in C.

%d represents an integer. It will be replaced by the content of the variable i that is provided in the array that follows it.

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

You can find more information in the Delphi documentation for SysUtils.Format, specifically in the sub-section regarding Format Strings.

like image 180
Ken White Avatar answered Oct 22 '22 11:10

Ken White


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

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

The format string placeholders specify the data type and formatting information. So, %d is used to display an integer value in decimal representation, and %s is used to indicate a string.

like image 27
David Heffernan Avatar answered Oct 22 '22 11:10

David Heffernan