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

Related Items

VFP and VBA.

The Visual FoxPro and Visual Basic for Applications languages are similar but there are annoying differences between them.

Read More

Text delimiters in VBA and VFP.

Visual Basic for Applications and Visual FoxPro delimiters for strings.

Read More

Text concatenation in VBA and VFP

Visual Basic for Applications and Visual FoxPro operators to concatenate text.

Read More

Text substrings in VBA and VFP

Visual Basic for Applications and Visual FoxPro functions to extract substrings from within a string of text

Read More

Trimming text in VBA and VFP

Visual Basic for Applications and Visual FoxPro functions to trim leading and trailing spaces from string of text

Read More