Re: Create a string with (n) copies of the same character



(O)enone wrote on 19 sep 2007 in microsoft.public.scripting.jscript:

I wish to create a function into which I pass a number, and it returns
a string containing that number of asterisks. So if I pass in the
number 5, it returns '*****'.

I can obviously do this by looping and adding a single asterisk to a
string for each iteration, but I'm sure JavaScript must offer a
cleaner way to do this.

Can anyone point me to a nice way to achieve this?

'This a school assignment?


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
.



Relevant Pages

  • Re: Performance Question
    ... Split is more efficient than actually looping through the string. ... second time (parsing it yet again) to assign the data to the array. ...
    (microsoft.public.vb.general.discussion)
  • Re: Truncate Left Characters in Cell Value
    ... Another quick way (no looping), ... Function Trunc(str As String) ... Sub foo() ... End Sub ...
    (microsoft.public.excel.programming)
  • Re: capture substring in the most efficient
    ... The source string has fixed length fields. ... recursive looping will certainly be unavoidable. ... that this always implies a sort of looping. ...
    (comp.lang.c)
  • Re: List to database
    ... I would certainly go with looping. ... With web apps, many small actions are ... I wonder how to trasfer this value to the database. ... conver the generic list into a string, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Read File into multi-dimensional array ignore whitespace
    ... you are splitting the string that is in $_. ... it is because you _are_ printing a scalar. ... but mapis just a foreachin disguise, so you are still looping. ...
    (comp.lang.perl.misc)

Loading