Visual Basic and Visual FoxPro functions create repeating characters

VBA

Space(), String()

VFP

Space(), Replicate(), PadL(), PadR(), PadC()

Visual Basic Syntax Notes

The Space() function generates a string of spaces. The String() function will generate a string of repeating characters. This example will produce 12 asterisks:

string(12, "*")

Visual Foxpro Syntax Notes

The Space() function has the same syntax as in Visual Basic and generates a string of spaces. The Replicate() function will generate a string of repeating characters. This example will produce a string of 10 dashes:

replicate("-", 10)

Visual FoxPro also has functions that will pad a string to a given length. The PadL(), PadR() and PadC() will add spaces or characters to an existing string and leave it left, right, or centre-aligned within a longer string. For example:

PadC("Test", 12, "-")

will pad "Test" out to 12 characters long with equal numbers of dashes on either side: "----Test----". This command used to be very useful for making pretty headers on plain typed reports.

Warning

The String() and Replicate() functions both take a character and a number as their parameters but the orders are reversed in FoxPro and Basic.

Changing characters  |  Text functions  |  Formatting text