Jump to content

String alignement question

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
SinXJon

SinXJon

    Newbie

  • Members
  • Pip
  • 4 posts
Hi guys ^^

I was wondering if anyone could help me with this problem. I'm pretty sure
Its not complicated, I just don't know how to do it. Basicly I have a loop
which gets information from a database and adds it to a string in a loop
for each records of the database. I also do a carriage return so that I have
1 record per line.

This I do all correctly, I have no problems with this. The only problem comes
when I want to put up my string in a JOptionPane or a InputBox.
The values aren't aligned.

I get values like:

1 Java 87 "One Awesome class"
2 VisualBasic 67 "little boring"
3 COBOL 100 "lol"


Basicly id like it better if I could put it up such as:

1 Java--------87----"One Awesome class"
2 VisualBasic--67----"little boring"
3 COBOL------100---"lol"
(Replace - by spaces)

If anyone could help me with this, it would be greatly appreciated..
I'm sure theres a method probably associated to a string to do it,
I just don't know which one :(

anyways thanks guys :)

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
I'm not sure there is a particular function that does what you are looking for, but you could create a function that add's `n` amount of spaces to the string...

#3
gszauer

gszauer

    Programmer

  • Members
  • PipPipPipPip
  • 113 posts
Boy, was that a confusing post...
How about some code to help us out?

~Aristotle said:

It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep Posted Image

#4
Arkie

Arkie

    Learning Programmer

  • Members
  • PipPipPip
  • 92 posts
use \\t to tab and allign the data in your string.