Try testing for the length of the string and then using the substr() function to get the part that you want for strings that are longer than desired.
-----Original Message----- From: Shishir K. Singh To: [EMAIL PROTECTED] Sent: 6/20/02 10:42 PM Subject: Formatting 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]