Repeat ( text ; numberOfTimes )
Repeats text number of times
Average rating: 4.0 (57 votes) Log in to vote
*COMMENT Visual Realisation
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
Repeats text the specified number of times.
This simple non-recursive calculation extends the limit of allowable repeats up to 161,999 (with a plain Substitute ( 10^numberOfTimes - 1 ; "9" ; text ) the limit is 404 repeats, while the obvious recursive function would be limited to 10,000 recursions).
Thomas Seidler, London, UK
Jun 27, 2009
For the OCD, here is one that doubles the string each time and uses tail-end recursion...
So you have 2^50k repeats possible - ha ha ha!! No point cluttering Brian Dunnings site with another CFunction doing the same thing, so i just add here for the lunatic fringe...
It should arrive at your desired length extremely rapidly!
It will take decimal numbers and round to nearest letter.
Repeat ( "abc ; " ; 7 ) => "abc ; abc ; abc ; abc ; abc ; abc ; abc ;"
0 -- "abc ; abc ; " ; 3.5 (_n -2 )/ 2
1 -- "abc ; abc ; abc ; abc ; " 1.75
2 -- "abc ; abc ; abc ; abc ; abc ; abc ; abc ; "
Case ( _n > 2 ; Repeat ( _string & _string ; _n/2 ) ; // now I'm sending a string twice as long, so n is halved
_n > 0 ; Left ( _string & _string ; Round ( _n * Length ( _string ) ; 0 ) ) ; // return final result
_ ) // end case - 0 or bad _n return empty
Mar 29, 2010
|Thank you so much for doing and posting this.|
Dan Smith, B.C. Canada
Aug 28, 2011
I was curious to know the performace difference between this function and this simple recursive function that produces the similar result:
numberOfTimes > 0 ;
text & RepeatB( text ; numberOfTimes - 1 )
Comparision of Repeat to RecursiveRepeat for various numberOfTimes values:
numberOfTimes comparison to RecursiveRepeat
001 10% slower
002 almost equal
005 160% faster
010 250% faster
100 1600% faster
Bottom Line: great custom function Michael!
Steve Lane, Devon, PA
Jan 10, 2013
|Some further thoughts on this problem here: http://www.soliantconsulting.com/blog/2013/01/power-division|
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.