repeating string

Richard Gaskin ambassador at fourthworld.com
Sat Feb 8 18:53:31 EST 2014


Nice, Peter.

Inspired by that I wondered if we might use the lineDel to some 
advantage here, and it turns out to be ever so slightly faster:

on mouseUp
    put 10000 into n
    -- test 1:
    put the millisecs into t
    repeat n
       put MakeString("#", 100) into r1
    end repeat
    put the millisecs - t into t1
    -- test 2:
    put the millisecs into t
    repeat n
       put MakeString2("#", 100) into r2
    end repeat
    put the millisecs - t into t2
    -- display results:
    put t1  && t2 && (r1=r2)&cr& r1 &len(r1) &cr& r2  &len(r2)
end mouseUp

function makeString tChar, n
    -- returns a string of n characters (tChar)
    -- no repeat loop!
    put cr into line n of m
    replace cr with tChar in m
    return m
end makeString

function makeString2 tChar, n
    set the linedel to tChar
    put tChar into line n of m
    return m
end makeString2


On my slow Mac that produces:

75 70 true
####################################################################################################100
####################################################################################################100

And if the char you need is either space or null, binaryEncode can 
produce a string of arbitrary length padded with either of those (and a 
whole lot more  - binaryEncode is quite a powerhouse of utility).

-- 
  Richard Gaskin
  Fourth World Systems
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the use-livecode mailing list