English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

it needs to be 45 characters when generated into my text file, another words i need a fixed length, and if only 30 chars are entered i need it space filled for another 15 chars making it equal 45....any advice? i'm new to CGI...here is my line of code:

print OUTF "Members Name: $FORM{'Name'}";

2007-03-16 07:07:09 · 2 answers · asked by tryingto 1 in Computers & Internet Programming & Design

2 answers

Basically what the other person said, but since I actually know perl, I can show you exactly how to do it. Get the length of $FORM{Name} with the length operator; if it's too long, use substr to truncate it. If it's too short, append some spaces to it. You don't need to use a for loop, the scalar x operator is simpler: ' ' x (45 - length $FORM{Name})

2007-03-16 08:45:42 · answer #1 · answered by undercoloteal 3 · 0 0

Well, I don't know which language you are using, but what I'd do is get the length of Name, then if it's >45, truncate it using left or substring function. If it's<45, make a loop:
for(i=length;<45;i++)append a blank to Name
That's what I'd do. Or if you have available printf function (from c),
printf("%' '45.45s", Name), I think this is the syntaxis (print Name with ' ' for a maximum width of 45 and no more than 45 chars.)

2007-03-16 15:22:46 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers