Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.format ?
#1
Hello Gintaras

I need to append a variable amount of zero's to a string variable. I can do it using function "for". After some reading in Qm help i found that function "format" maybe could do it too(?) just cant work it out.

How i do it.

Macro Macro2
Code:
Copy      Help
str s = "5"
int z = 2  ;; amount of zero's

for(_i 0 z) s + "0"

out s
#2
Macro Macro1820
Code:
Copy      Help
str s = "5"
int z = 2 ;; amount of zero's

s.set('0' s.len z)

out s

With str.format also possible in QM 2.3.3.
Macro Macro1821
Code:
Copy      Help
str s = "5"
int z = 2 ;; amount of zero's

s.formata("%.*m" z '0')

out s
But in this case better is str.set. Your code also OK, when z is not too big. Even shorter is: rep(z) s + "0"
#3
Thank you.


Forum Jump:


Users browsing this thread: 1 Guest(s)