How to create repeating character strings in Revolution

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9
Joined: Tue Feb 10, 2009 2:14 am

How to create repeating character strings in Revolution

Post by BillJames » Tue Feb 10, 2009 2:36 am

Could someone explain why the following statements give different results:

put format("%40c",space) into t40Spaces
put format("%40c"," ") into t40Spaces
put format("%40c",32) into t40Spaces
put format("%40c",charToNum(" ")) into t40Spaces

The last two statements do what I expect; puts a string with 40 spaces into the variable t40Spaces. The first two statements create a 40 space string ending with the character "8".

Also, is there another simple method using revolution to create strings of repeating characters other than using the format statement.

I believe there are other languages such as Python that overload operators such as "*" to do this making 40*' ' a string with 40 space characters. I do not see an equivalent in Revolution.


Posts: 62
Joined: Sat Feb 17, 2007 4:56 am
Location: Australia

Post by gmccarthy » Tue Feb 10, 2009 7:05 am

These are not really repeat characters using the format statement.
From the dictionary:
The corresponding value is treated as an ASCII value and translated to the corresponding character. If a charLength is specified, one fewer leading spaces are added to make it charLength characters long. For example, the incantation %2c transforms 65 to " A" (65 is the ASCII value of the character "A").

eg. put format("%10c",65) creates a 10 character string made up up 9 leading spaces followed by a capital A.

Notice the value after the comma is supposed to be an ascii value.
Thats why your last 2 statements work properly.
The first two don't follow the rules, so they result in unexpected results.

To create repeated strings just create a simple repeat loop.


put fGetRepeatedString("ABC",6) --"ABCABCABCABCABCABC'

function fGetRepeatedString pString,pRepeatNum
local tTotalString
repeat pRepeatNum times
put pString after tTotalString
end repeat
return tTotalString
end fGetRepeatedString

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”