|
-
Mar 27th, 2005, 10:56 PM
#1
Thread Starter
Fanatic Member
[Solved] Padding
VB Code:
A very long text, so to speak [ Ok ]
Short text [ Ok ]
Another very very very very long text, hey. [ Ok ]
text [ Ok ]
I need help displaying something like this on the console. \t seems not align them when displaying short/long texts. Thanks a lot in advance.
Last edited by nebulom; Mar 28th, 2005 at 08:25 PM.
-
Mar 27th, 2005, 11:05 PM
#2
Thread Starter
Fanatic Member
Re: Padding
Something like this in C
VB Code:
#include <stdio.h>
int main(){
printf("%-50s[ Ok ]\n","A very long text, so to speak"," ");
printf("%-50s[ Ok ]\n","Short text"," ");
printf("%-50s[ Ok ]\n","Another very very very very long text, hey."," ");
printf("%-50s[ Ok ]\n","tex"," ");
return 0;
}
Help? Thanks.
-
Mar 28th, 2005, 11:16 AM
#3
Re: Padding
I might be wrong here. But I don't think there is sutch a function in Java. At school we just made a function that used the MyString.Length() function to check how long the string was, and then used a loop to add the rest of the blank spaces after it, to the the next thing ligned up.
ØØ
-
Mar 28th, 2005, 08:21 PM
#4
Thread Starter
Fanatic Member
Re: Padding
Thanks, I'll just do it that way. Again, thanks.

edit: Btw, I've got this... This might not be good so please feel free to criticize.
VB Code:
String temp="Generating "+t.getName(),temp2="";
temp2=temp;
for(int i=temp.length();i<40;i++) temp2+=" ";
System.out.print(temp2);
. . .
where t.getName() is the name to be generated. It could be something else string.
Last edited by nebulom; Mar 28th, 2005 at 08:32 PM.
-
Mar 29th, 2005, 01:21 PM
#5
Re: [Solved] Padding
Nothing wrong with that. Just that, if you are using it often, I would have made it a function. LIke at school, we made a print class, that had a LOT of static functions for printing and converting stuff back and forth to print out to the screen.
But again. I can't see anything wrong with what you did.
ØØ
-
Mar 29th, 2005, 05:55 PM
#6
Frenzied Member
Re: Padding
 Originally Posted by nebulom
Btw, I've got this... This might not be good so please feel free to
If you use a single String you may want to check your performance and memory usage.
Could get substantial as Strings are immutable and thus a new String is being created for each iteration.
-
Mar 29th, 2005, 08:30 PM
#7
Thread Starter
Fanatic Member
Re: [Solved] Padding
Thanks a lot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|