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

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

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

Post by ale870 » Tue Aug 11, 2009 8:35 pm

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!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Tue Aug 11, 2009 8:50 pm

Ale,

try

Code: Select all

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

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Post by ale870 » Tue Aug 11, 2009 8:53 pm

Thank you, but I'm already using:
repeat for x times

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

Thank you!

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Wed Aug 12, 2009 9:42 am

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

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Post by Mark Smith » Wed Aug 12, 2009 11:55 am

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

Post Reply