Hi,
I need to format a string in a fixed width field. The string may be less than the
length of the format, or may be greater. If less, then it should get padded with
spaces (left or right justified , like using - in sprintf), if greater, then the
string should get truncated to the exact length.
eg $myVar = 'ABCDEFGHIJKLMNOP';
$newVar = sprintf("%10s,$myVar);
$newVar should have 'ABCDEFGHIJ'; # But has the full length i.e. 'ABCDEFGHIJKLMNOP'
eg $myVar = 'ABCD'; (Right Aligned, padded with spaces)
$newVar = sprintf("%10s,$myVar);
$newVar should have ' ABCD'; # Works
eg $myVar = 'ABCD'; (Left Aligned, padded with spaces)
$newVar = sprintf("%-10s,$myVar);
$newVar should have 'ABCD '; # Works
I am not able to lay my finger on the correct format to achieve 1st and the 2nd with
the same format. Am I missing something , or is there another way out? Any help would
be greatly appreciated.
Thanks
Shishir
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]