Printf and Format Operations

Parent Previous Next

VisualSim                                                                                                                                    

Printf and Format Operations

 

Function & Argument Type(s)

 

Description

 

Example

 

newString ("%s = %d")

String Formatting:

This format is used for equating a string to an integer. This said string should be stored in an array.

 

Format          = newString ("%s = %d")

Array           = {"John"}

Array           = Array.append (35)

Text          &nbsp12 = printf (Format, Array)

SEND (output, Text)

prints: John = 35

newString ("%s%n")

String Formatting:

This format is used to place a string where %s is used. If we want to use multiple strings , then we have to use an array of strings in Text

 

Format          = newString ("My name is: %s%n")

Text            = printf (Format, "John")

SEND (output, Text)

prints: My name is: John

newString ("%2$s")

String Formatting:

This is used for selecting an element stored at desired position in an array. %(number)$s selects the element located at (number) 

Format          = newString ("%2$s")

Array           = {32}

Array           = Array.append ("Hello")

Text            = printf (Format, Array)

SEND (output, Text)

prints: "Hello"

newString ("%d")

Formatting an Integer:

Default format

Format          = newString ("%d")

Text            = printf (Format, 93)   

SEND (output, Text)

prints: 93

newString ("|%20d|")

Formatting an Integer:

This format is used for creating a width of the said number by adding spaces to the left. The “|” symbol can be replaced with any other character and that will be added to the starting and ending of the string.

Format          = newString ("|%20d|")

Text            = printf (Format, 93)   

SEND (output, Text)

prints: |                  93|

newString ("|%-20d|")

Formatting an Integer:

This format is used for creating a width of the said number by adding spaces to the right. The “|” symbol can be replaced with any other character and that will be added to the starting and ending of the string.

Format          = newString ("|%-20d|")

Text            = printf (Format, 93)   

SEND (output, Text)

prints: |93                  |

newString ("|%020d|")

Formatting an Integer:

Here a 0 has been added before the number so instead of spaces, 0 will be added 18 times to the left of the number so that width becomes 20.

Format          = newString ("|%020d|")

Text            = printf (Format, 93)    

SEND (output, Text)

prints: |00000000000000000093|

newString ("|% d|")

Formatting an Integer:

This just adds the symbol to the start and end of the string 

Format          = newString ("|% d|")

Text            = printf (Format, 93)  

SEND (output, Text)

prints: | 93|

newString ("|%.3f|")

Formatting an Integer:

This format is used for specifying the number of decimal points we want to be displayed

Format          = newString ("|%.3f|")

Text            = printf (Format, 93.12345)

SEND (output, Text)

prints: |93.123|

newString ("|% d|")

Formatting an Integer:

Default format

Format          = newString ("|% d|")

Text            = printf (Format, -36) 

SEND (output, Text)

prints: |-36|

newString ("|%,d|")

Formatting an Integer:

For the US locale it is “,”

Format          = newString ("|%,d|")

Text            = printf (Format, 10000000) 

SEND (output, Text)

prints: |10,000,000|

newString ("|%(d|")

Formatting an Integer:

This format is used for remove negative sign and place that number in brackets

Format          = newString ("|%(d|")

Text            = printf (Format, -36)      

SEND (output, Text)

prints: |(36)|

newString ("|%o|")

Formatting an Integer:

This format is used for obtaining octal value of the integer entered

Format          = newString ("|%o|")

Text            = printf (Format, 93)

SEND (output, Text)

prints: |135|

newString ("|%x|")

Formatting an Integer:

This format is used for obtaining hex value of the integer entered

Format          = newString ("|%x|")

Text            = printf (Format, 93)       

SEND (output, Text)

prints: |5d|

newString ("|%#o|")

Formatting an Integer:

This format prints octal numbers with a leading "0"

Format          = newString ("|%#o|")

Text            = printf (Format, 93)       

SEND (output, Text)

prints: |0135|

newString ("|%#x|")

Formatting an Integer:

This format prints hex numbers with a leading "0x"

Format          = newString ("|%#x|")

Text            = printf (Format, 93);      

SEND (output, Text)

prints: |0x5d|

newString ("|%#X|")

Formatting an Integer:

This format prints hex numbers with a leading "0x" and alphabets in uppercase

Format          = newString ("|%#X|")

Text            = printf (Format, 93);      

SEND (output, Text)

prints: |0X5D|

  

newString("|%s|")

  

String Formatting:

This format just adds the symbol “|” at the beginning and ending of the string. “|” can be replaced by any other characters

 

Format          = newString ("|%s|")

Text            = printf (Format, "Hello World")  SEND (output, Text)

prints: |Hello World|

 newString ("|%30s|")   

String Formatting:

This format is used for specifying a particular field length by creating empty spaces to the left of the string.

Format          = newString ("|%30s|")

Text            = printf (Format, "Hello World") 

SEND (output, Text)

prints: |                   Hello World|

  newString ("|%-30s|")   

String Formatting:

This format is used for specifying a particular field length by creating empty spaces to the right of the string.

Format          = newString ("|%-30s|")

Text            = printf (Format, "Hello World”)

SEND (output, Text)

prints: |Hello World                   |

  newString ("|%.5s|")   

String Formatting:

This format is used for specifying Maximum Number of Characters to be printed

 

Format          = newString ("|%.5s|")

Text            = printf (Format, "Hello World")

 SEND (output, Text)

prints: |Hello|

 newString ("|%30.5s|")   

String Formatting:

This format is used for specifying width and Maximum Number of Characters to be printed

  

Format          = newString ("|%30.5s|")

Text            = printf (Format, "Hello World") 

SEND (output, Text)

prints: |                         Hello|

 

Reference RegEx Constant Model:     


 

 

Created with the Personal Edition of HelpNDoc: Free CHM Help documentation generator