Repeat some characters n times in ObjectScript.

Primary tabs

ObjectScript, Caché
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.
  • 0
  • 0
  • 120
  • 4
  • 2

Answers

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

set myVar="",$piece(myVar,"=",31)=""  ;repeat = 30 times

 

works also with multiple characters :

USER>set myVar="",$piece(myVar,"=?",31)=""
 
USER>write myVar
=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?
 

Or

USER>k temp  set $LIST(temp,31)="",myVar=$LISTTOSTRING(temp,"=?",1)
USER>w myVar
=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?
 

Or

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

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