Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Format string...
#1
Once again I've got my little hack way of doing this...but I want to see if there is a nice easy QM way that I missed in the help file Smile

Program saves files with this number suffixed on the file name:
00-99 (just formatted with leading zero)
but then:
100 is outputted as "a0"
101 = a1
102 = a2
...
110 = b0
120 = c0

up to 159 =f9
#2
nothing fancy, probably similar to your method

Macro
Code:
Copy      Help
str s = "9"
if s.len > 2
,str s2.get(s 1 1)
,s2[0] = ('a' + val(s2))
,s.replace(s2 0 2)
else
,if s.len < 2
,,s - "0"
out s
#3
If need only < 160

Macro Macro1267
Code:
Copy      Help
out
int i
for i 0 160
,str s.format("%x%i" i/10 i%10)
,out s
,

%x formats hexadecimal number, 0 to f.
#4
Exactly what I need.

Function Function54
Code:
Copy      Help
out
int i=122
str s.format("%x%i" i/10 i%10)
out s

I didn't think of dividing by 10 like that and then didn't know you could grab 10%...nice work.

Thanks,
Jimmy Vig
#5
int Cart=75321
int Cut=100
str sCart.format("N:\%07i%x%i.wav" Cart Cut/10 Cut%10)
out sCart


I don't know if this can be done, but can the length of the format be a variable?

Like in the example above...if I want the length to be 7 places with leading zeros, can I use a variable to format?
#6
Call format() 2 times. At first format "N:\%07i%x%i.wav", then use it in the next format() as first argument. Or use from().

int Cart=75321
int Cut=100
str sCart.format(_s.from("N:\%0" 7 "i%x%i.wav") Cart Cut/10 Cut%10)
out sCart
#7
Thanks. Exactly what I need!


Forum Jump:


Users browsing this thread: 1 Guest(s)