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.
Discussion (6)0
Comments
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
Thanks.
set myVar="",$piece(myVar,"=",31)="" ;repeat = 30 times
works also with multiple characters :
USER>set myVar="",$piece(myVar,"=?",31)=""
USER>write myVar
=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?
USER>write myVar
=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=?
Tricky!
Thanks.
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