Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
REPLICATE()
This function lets you create a string composed of multiple copies of another string.
cNewString = REPLICATE( cString, nTimes )
Parameter |
Value |
Meaning |
cString |
Character |
The string to be repeated to produce the result. |
nTimes |
Numeric |
The number of times to repeat cString. |
cNewString |
Character |
A string consisting of nTimes copies of cString. |
REPLICATE()
is handy for allowing you to use proportional fonts for input without ending up with too many characters. By specifying an InputMask (PICTURE clause in 2.x) of REPLICATE(“X”, LEN(<field>)), the user can’t enter more characters than the field holds.
In the little-known-facts department, you can pass an entire string to REPLICATE()
, not just a single character. We suspect many experienced Xbase programmers don’t realize this.
? REPLICATE("X", 30) && Returns a string of 30 X's
? REPLICATE("Fox", 3) && Returns "FoxFoxFox"