The following Mathematica function f creates a string of whitespace of length n.
f[n_]:=Fold[StringJoin,"",Array[" "&,n]]
There must be a zillion alternatives to create this function.
How would you have done it?
The following Mathematica function f creates a string of whitespace of length n.
f[n_]:=Fold[StringJoin,"",Array[" "&,n]]
There must be a zillion alternatives to create this function.
How would you have done it?
This is about twice as fast as Thies Heidecke's function,but not nearly as fast as Sjoerd's.For large
n
a longer initial string is helpful. This is faster than Sjoerd's method forn > 10000
:By the way: you should be aware that this type of question is frowned upon in the faq:
Don't be surprised if the question is closed.
Spacer
andInvisible
are also be useful for creating whitespace, with differences in how you specify the size of the space.Edit: since @ is as idiomatic as @@ and a bit faster (thanks to Mr.Wizard for benchmarking) and shorter i updated the solution.