Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
formatting — Gideros Forum

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# formatting

Member
edited September 2020
local mycolor = 0x0000ff

how can I put it in a string without it being converted to 255? I would like to get 0x0000ff or at least 0000ff. I tried:

print(tostring(mycolor)) -- 255
print(mycolor) -- 255
print(string.format("%q", mycolor)) -- "255"

Thank you.
my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Tagged:

• Member
 `print( ("0x%06x"):format(math.random(0xffffff)) )`
or
 `print( ("%x"):format(math.random(0xffffff)) )`

Likes: MoKaLux

+1 -1 (+1 / -0 )Share on Facebook
• Member
thank you
my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
• Member
this kind of notation is scifi for me, so perhaps you might also prefer:
string.format("%x",0xffffff)
which is the same but written differently.

Likes: MoKaLux, antix

+1 -1 (+2 / -0 )Share on Facebook
• Member
true, your example is also perfect thank you keszegh.
my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
• Member
keszegh said:

this kind of notation is scifi for me, so perhaps you might also prefer:
string.format("%x",0xffffff)
which is the same but written differently.

It basically means this:
 ```local myString = "0x%06x" -- means print "0x" as regular string, then add converted hex number with 6 leading zeros -- so if you call "print(("%x"):format(0x0000ff))" then you will get just "ff", but with "%06x" result is "0000ff" print(myString:format(0x0000ff)) -- or print(string.format(myString, 0x0000ff))```

Likes: MoKaLux

+1 -1 (+1 / -0 )Share on Facebook
• Maintainer
 ```local s="Hello" print(("%02X"):rep(#s):format(s:byte(1,#s)))```