Re: Printf puzzlement

new topic     » goto parent     » topic index » view thread      » older message » newer message

From the docs:

Field widths can be added to the basic formats, e.g. %5d, %8.2f, %10.4s. The number before the decimal point is the minimum field width to be used. The number after the decimal point is the precision to be used for numeric values.

There's no format specifier to clip strings to a given length, so you would need to do that using brackets:

printf(1,"%7s",{test_sequence[1..7]} 

Of course, the above would fail if the test_sequence was shorter than 7, so perhaps:

printf(1,"%7s",{test_sequence[1..math:min(7,length(test_sequence))]} 

If test_sequence is shorter than 7, then spaces will be added to the start of the string to make it 7 characters long.

printf(1,"%7s",{test_sequence}) 

Also, look at text:format() and display(), they can often do more than printf() with less coding.

display("[:4]",{test_sequence}) 

The above will clip the string to the first 4 characters, and will just print it if it has less than 4 characters. See what i mean about doing more with less?

display("[:4>]",{test_sequence}) 

Above, we right-justify the printout, so blank space(s) are added to the start of the string to make it take up 4 character spaces. There are lots of other possibilities, as well. display() comes in very handy, especially when formatting reports. It's easy to position things exactly where you want them.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu