Page 1 of 1

How to create a string like "====================="

Posted: Tue Aug 11, 2009 8:35 pm
by ale870
Hello,

is there any function to create a string with a lot of copies of a specific character? For example:

copy("A", 5) --> "AAAAA"

Thank you!

Posted: Tue Aug 11, 2009 8:50 pm
by bn
Ale,

try

Code: Select all

repeat 5
  put "A" after tCollect
end repeat
tCollect is now ->"AAAAA"
regards
Bernd

Posted: Tue Aug 11, 2009 8:53 pm
by ale870
Thank you, but I'm already using:
repeat for x times

I don't know if a shorter (and faster!) function exists.

Thank you!

Posted: Wed Aug 12, 2009 9:42 am
by Klaus
Hi ale870,

no there is no other way to do this!
But you can save some typing by simply writing:

Code: Select all

...
repeat 5
  put "x" after my_string_with_x
end repeat
...

Best

Klaus

Posted: Wed Aug 12, 2009 11:55 am
by Mark Smith
The thing is to build up your collection of such functions in a library, so you only have to write them once.

This means that you need to generalise them:

Code: Select all

function stringRep pString, pNumReps
  put empty into tRepString
  repeat pNumReps
    put pString after tRepString
  end repeat
  return tRepString
end stringRep
Best,

Mark Smith