Thousands separator in a number string

I can’t figure out how to format my text so my scores show up with a thousands separator. Any tips? string.format seems to be useless for that. [import]uid: 10835 topic_id: 3817 reply_id: 303817[/import]

Try string.gmatch or string.gsub with regex.

string.gmatch:
http://developer.anscamobile.com/node/3200

string.gsub:
http://developer.anscamobile.com/node/3222

patterns:
http://developer.anscamobile.com/content/strings#Patterns
If you haven’t used it before, it will take some tweaking to become accustomed to it. [import]uid: 11024 topic_id: 3817 reply_id: 11589[/import]

Come to think of it, maybe that’s unnecessary.

Since you’re only dealing with something that only displays scores, you can check for the string length and then just split strings after every third digit from the right. Then recombine, display, or print them with a comma and so on. [import]uid: 11024 topic_id: 3817 reply_id: 11591[/import]

Here, I put together this function.

[lua]–Can be whatever
score = 1030003
print (fixScore(score))[/lua]

[lua] function fixScore(score)
–Number of loops
loops = string.sub(((string.len(score)/3)), 1,1)

–Find out the leading characters
leadingChars = math.fmod (string.len(score), 3)
–Offset loop when there’s no leading characters
if (leadingChars == 0) then
loops = loops - 1
reach = 3
elseif (leadingChars == 1) then
reach = 1
elseif (leadingChars == 2) then
reach = 2
end

–Reverse because it’s easier to count backwards
scoretemp = string.reverse(score)
scorenew = “”

–Add commas at interval
for i=1, loops, 1 do
scorenew = scorenew … (string.sub (scoretemp, ((i*3)-2), i*3) … “,” )
end

–Recombine
scorenew = string.sub(score, 1, reach) … string.reverse(scorenew)

–Send new value
return scorenew
end[/lua]
[import]uid: 11024 topic_id: 3817 reply_id: 11594[/import]

Thanks for the response, it’ll make my life easier. I forgot to ask before, but in drawing software you can choose one color to fill the font and another for the outline. I’m not clear if you can do the outline in Corona. Is this supported?

I’m in dire need to give my fonts a black outline to make them pop, otherwise I’m gonna have to use bitmap fonts, which I was trying to avoid. [import]uid: 10835 topic_id: 3817 reply_id: 11619[/import]