Written by

CHR (Liège - Belgium/Belgique)
Question Michel Bruyère · Nov 27, 2019

Repeat some characters n times in ObjectScript.

Hello,
 
I'm looking for a simple commons method or operator that allows me to repeat some characters  n times. I know I could write this using a for loop, but I wish to avoid for loops whenever necessary and a simple direct method should exist somewhere.
 
Best Regards.

Comments

Alexander Koblov · Nov 27, 2019

The best I know is $TR/$J combination:

USER>w $TR($J("",10)," ","x") ; repeat x 10 times xxxxxxxxxx USER>w $TR($J("",5)," ","y") ; repeat y 5 times yyyyy

0
Danny Wijnschenk · Nov 27, 2019
set myVar="",$piece(myVar,"=",31)=""  ;repeat = 30 times

works also with multiple characters :

USER>set myVar="",$piece(myVar,"=?",31)=""
 
USER>write myVar
=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?
 
0
Iain MacDonald  Nov 28, 2019 to Danny Wijnschenk

Or

USER>k temp  set $LIST(temp,31)="",myVar=$LISTTOSTRING(temp,"=?",1)
USER>w myVar
=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?
 
0
Alexey Maslov  Nov 28, 2019 to Iain MacDonald

Or

USER>w $replace($j("",30)," ","=?")
=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?

USER>w $l(x,"=?")
31 ; as in previous samples
0