Results 1 to 7 of 7

Thread: [Solved] Padding

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Resolved [Solved] Padding

    VB Code:
    1. A very long text, so to speak               [ Ok ]
    2. Short text                                  [ Ok ]
    3. Another very very very very long text, hey. [ Ok ]
    4. 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.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Padding

    Something like this in C
    VB Code:
    1. #include <stdio.h>
    2. int main(){
    3.     printf("%-50s[ Ok ]\n","A very long text, so to speak"," ");
    4.     printf("%-50s[ Ok ]\n","Short text"," ");
    5.     printf("%-50s[ Ok ]\n","Another very very very very long text, hey."," ");
    6.     printf("%-50s[ Ok ]\n","tex"," ");
    7.     return 0;
    8. }
    Help? Thanks.

  3. #3
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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.




    ØØ

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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:
    1. String temp="Generating "+t.getName(),temp2="";
    2.                 temp2=temp;
    3.                 for(int i=temp.length();i<40;i++) temp2+=" ";
    4.                 System.out.print(temp2);
    5. . . .
    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.

  5. #5
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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.



    ØØ

  6. #6
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Padding

    Quote 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.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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
  •  



Click Here to Expand Forum to Full Width