String.repeat: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Useful Function}} __NOTOC__ This function repeats a substring n times. ==Syntax== <syntaxhighlight lang="lua"> string string.repetition ( string what, int n ) </syntaxhighlight> ===Required Arguments=== * '''what''': String you want to repeat * '''n''': Number of times you want the string to repeat ===Returns=== Returns repeated string ==Code== <section name="Shared script" class="both" show="true"> <syntaxhighlight lang="lua"> function string.repetition(what, n)...")
 
m (Moved string.repeat to string.repetition due to syntax issues)
Tag: New redirect
 
Line 1: Line 1:
{{Useful Function}}
#REDIRECT [[string.repetition]]
__NOTOC__
This function repeats a substring n times.
 
==Syntax==
<syntaxhighlight lang="lua">
string string.repetition ( string what, int n )
</syntaxhighlight>
 
===Required Arguments===
* '''what''': String you want to repeat
* '''n''': Number of times you want the string to repeat
 
===Returns===
Returns repeated string
 
==Code==
<section name="Shared script" class="both" show="true">
<syntaxhighlight lang="lua">
function string.repetition(what, n)
    local out = ''
    for i=1, n do
        out = out..what
    end
    return out
end
</syntaxhighlight>
</section>
 
==Example==
<section name="Shared script" class="both" show="true">
<syntaxhighlight lang="lua">
iprint('//'..string.repetition('*',14)..'\\')
iprint('||'..string.repetition('*',4)..' Test '..string.repetition('*',4)..'||')
iprint('\\'..string.repetition('*',14)..'//')
</syntaxhighlight>
</section>
 
Author: Tracer
 
==See Also==
{{Useful_Functions}}

Latest revision as of 08:22, 6 June 2024

Redirect to: