Function Names
replicate, replicate characters
Description
The function replicate() repeats the specified string by the number provided.
- If the 2nd parameter is 0 or negative, then a blank string is returned.
- If the 2nd parameter is 1, then the original string will be returned.
- If the 2nd paramterr is 2, thenthe contents will be repeated once, and so forth.
The function replicate characters() repeats the specified string until the specified number of characters has been reached.
- If the 2nd parameter is 0 or negative, then a blank string is returned.
- If the 2nd parameter is 1, then 1 character is returned
- If the 2nd parameter is a multiple of the length of the string, then the string wil be replicated until the specified length has been reached.
- If the specified number is not a multiple of the number of characters of the string, then the resulting string ends with a truncated part of the original string.
Note: The count will be recognized as an integer and will be rounded down if needed.
Call as: function
Restrictions
Indirect parameter passing is disabled
Parameter count
1
Parameters
No. | Type | Description |
1 input |
string |
String
This is the source string to be replicated
|
2 input |
numeral |
Replication or character count
Specifies the number of repetitions or characters in the final string
|
Return value
Type | Description |
string |
Replicated string
Specified replication or character count |
Examples
echo( replicate( Café, 10 ) );
echo( replicate characters( Café, 10 ) );
Output
CaféCaféCaféCaféCaféCaféCaféCaféCaféCafé
CaféCaféCa
Try it yourself: Open
LIB_Function_replicate.b4p in
B4P_Examples.zip. Decompress before use.