String$ ( string$,repeat )
Parameters
|
string - the text to repeat repeat - how many copies to join together |
Description
|
Returns a string made by repeating another string a number of times. String( "ab",3 ) gives "ababab". A repeat count of 0 or less gives an empty string, so a calculated count that goes negative is harmless. The classic use is drawing with text. String( "=",40 ) rules a line under a heading, String( "*",hearts ) draws a health bar, and String( " ",n ) indents a line by a variable amount. In a text-mode debug overlay a repeated block character makes a perfectly serviceable progress bar - just work out the count as a fraction of the total. It also builds padding for the leading-zero trick: Right( String( "0",4 )+n,4 ) gives you a four-digit number with zeros in front. Note that the repeat count multiplies the whole string, not a single character, so String( "-+",5 ) gives you an alternating pattern. See also: LSet, RSet, Chr, Len. |
Example
; String Example ; -------------- ; String$ builds a new string by repeating a source string n times. ; A ruled-off game-over banner Print String$("=",40) Print "GAME OVER - Robo scored 1250" Print String$("=",40) Print "" ; A quick text health bar: filled blocks plus empty ones health=7 Print "Health: ["+String$("#",health)+String$("-",10-health)+"] "+health+"/10" ; Longer strings repeat too Print "" Print "Battle cry: "+String$("Waha! ",3) Print "" Print "Press any key to close the example" WaitKey End
Index