You like blanks() but life isn't made only of blanks. You will love strrepeat()
strrepeat() concatenates a character or a string or a set of strings or by
default a blank, respectively with themselves, a given number of times, or up to
a given number of characters or up to the length of a given text template.
See below for a full help, description, and examples.
RESULTS OF EXAMPLES
-------------------
-->// Blanks:
--> '|' + strrepeat(9) + '|'
ans =
| |
--> '|' + strrepeat([ 2 5 ; 4 8]) + '|'
ans =
!| | | | !
!| | | | !
--> '|' + strrepeat(['abc' ; '1234567']) + '|'
ans =
!| | !
!| | !
-->// Text with UTF-8 characters:
-->strrepeat('éüçñ実またちこんфий', 2)
ans =
éüçñ実またちこんфийéüçñ実またちこんфий
-->// One text, various repeating rates:
--> strrepeat('.', [2 5 ; 0 8])
ans =
!.. ..... !
! ........ !
--> strrepeat('-.', [3 -3 ; 5 -5])
ans =
!-.-.-. -.- !
!-.-.-.-.-. -.-.- !
--> strrepeat('.', ['abc' '1234567'])
ans =
!... ....... !
--> strrepeat(['A' ''], -7) // => error
!--error 10000
strrepeat: repeating the empty "" can't reach 7 characters!
-->// One repeating rate, various texts:
--> strrepeat(['-' '~' ; '-.' '~.'], 5)
ans =
!----- ~~~~~ !
!-.-.-.-.-. ~.~.~.~.~. !
--> strrepeat(['-' '~' ; '-.' '~.'], -9)
ans =
!--------- ~~~~~~~~~ !
!-.-.-.-.- ~.~.~.~.~ !
--> strrepeat(['-' '~' ; '-.' 'ab'], 'abcdefg')
ans =
!------- ~~~~~~~ !
!-.-.-.- abababa !
-->// Element-wise repeating rates:
--> '|' + strrepeat(['' '-.' '/\' '0-' 'cB'], [8 5 0 4 -11]) + '|'
ans =
!|| |-.-.-.-.-.| || |0-0-0-0-| |cBcBcBcBcBc| !
------------------------------------------------------------------
-->strrepeat
Repeats a text pattern n times or up to a n-characters length
SYNTAX
strrepeat // Displays this help
R = strrepeat(N) // R(I) = N(I) blanks
R = strrepeat(ST) // R(I) = length(ST(I)) blanks
R = strrepeat(T, N) // R(I) = T(I) repeated N(I)>0 times
// R(I) = T(I) repeated up to |N(I)<0| characters
R = strrepeat(T, ST) // R(I) = T(I) repeated up to length(ST(I)) characters
// ... where I stands for i, or (i,j), or (i,j,k..)
PARAMETERS
T : Scalar, vector, matrix or hypermatrix of text to be repeated.
By default, T = " ". UTF-8 characters are accepted.
N : Scalar, vector, matrix or hypermatrix of integers.
If N is a scalar while T is not so, N is used for every T components.
If T is a scalar while N is not so, T is repeated according to
each N component.
If N and T are not scalars, they must have the same sizes.
ST: Scalar, vector, matrix or hypermatrix of texts used as templates,
setting N = length(ST).
If T and ST are not scalars, they must have the same sizes.
R : Scalar, vector, matrix or hypermatrix of repeated text.
R has the sizes of the largest input T, N, or ST.
R = [] if T, N or ST is [].
DESCRIPTION
From a character, a word or a text, or from each component of a
matrix of chars and words and texts, strrepeat() concatenates it
with itself a) either as many times n as specified, or b) as many
times as to reach a given number n of characters. In the latter
case, if n is not a multiple of the item's length, the result of
the concatenation is trimmed on the right to n characters.
When no item to repeat is specified, " " is considered. Hence,
- strrepeat(n) is equivalent to blanks(n). However,
- strrepeat() is vectorized, while blanks() is not.
- strrepeat() is applicable to any character or string, whereas
blanks() generates exclusively white strings.
- strrepeat() can take strings as templates, while blanks() cannot.
NOTE: UTF-8 characters are supported.
WARNING: If a text is empty and must be repeated to reach a non
null length, an error occurs.
SEE ALSO
blanks : http://help.scilab.org/docs/5.5.2/en_US/blanks.html
strcat : http://help.scilab.org/docs/5.5.2/en_US/strcat.html
strsubst: http://fileexchange.scilab.org/toolboxes/294000
REFERENCE:
Comments, scoring and bug reports are welcome on
http://fileexchange.scilab.org/toolboxes/365000
EXAMPLES
// Blanks:
'|' + strrepeat(9) + '|'
'|' + strrepeat([ 2 5 ; 4 8]) + '|'
'|' + strrepeat(['abc' ; '1234567']) + '|'
// Text with UTF-8 characters:
strrepeat('éüçñ実またちこんфий', 2)
// One text, various repeating rates:
strrepeat('.', [2 5 ; 0 8])
strrepeat('-.', [3 -3 ; 5 -5])
strrepeat('.', ['abc' '1234567'])
strrepeat(['A' ''], -7) // => error
// One repeating rate, various texts:
strrepeat(['-' '~' ; '-.' '~.'], 5)
strrepeat(['-' '~' ; '-.' '~.'], -9)
strrepeat(['-' '~' ; '-.' 'ab'], 'abcdefg')
// Element-wise repeating rates:
'|' + strrepeat(['' '-.' '/\' '0-' 'cB'], [8 5 0 4 -11]) + '|'