Hi All,
I am using a String formatting which separates two strings using the "\t" (tab) character like below:
String _str = "col1" + "\t" + "col2" + "\t" + "col3";

I get the following output:
col1 col2 col3.

this is fine. But because i have a horizontal restriction to abide to. i need to control the tab size or the spaces left blank the "\t". i.e I wish to have col1, col2, col3 closer to each other than what i caused by the tab.

Please help! Urgent issue.

Thanks,
Ashok.

"\t" will automatically take a tab, so if you need less space open, you shouldn't use that. you may try by replacing the "\t" with a couple of spaces, or try formatted output.

Hi, Thanks for your feedback. I have tried with spaces but it doesnt give the desired output. He indentation falls apart in the next rows.

You mentioned trying out formatted output. Could you explain this to me.

Thanks,
Ashok.

Well, don't just use spaces on your own.

Try formatting as he suggested. Take a look at
String.format()
to format the String before output or
PrintStream.printf()
to format the String during output (System.out is a PrintStream if it is System.out that you are using).

Hi Masijade,

Could you please help me in understanding the String.format() more closely. I am in urgent need. Could you help by giving some examples.

Thanks,
Ashok.

Hi Masijade,

Could you please help me in understanding the String.format() more closely. I am in urgent need. Could you help by giving some examples.

Thanks,
Ashok.

the api's are allways a good place to start, otherwise there's allways google.

the intention of this forum is to learn for yourself, with guidance from part of the other users. by making mistakes and have other people looking into it, not by letting other people write you the code you want to have.

look into the api's and check how it works, try writing what you want it to do and if it still does not give you the result you need, post your code and error here.

Aah! I found how it can be done using String.format() but the issue is my company has jdk1.4. So I have to manage within it. Could you please help?

Hi Masijade,

Could you please help me in understanding the String.format() more closely. I am in urgent need. Could you help by giving some examples.

Thanks,
Ashok.

Read this carefully

http://java.sun.com/javase/6/docs/api/java/util/Formatter.html#syntax

And then, as already said, attempt to do it yourself, if you have problems post what you have and we will attempt to help you correct it. And that link contains examples and a complete explanation of the format string to be used in the format method, so it will contain more than enough information for you to be able to accomplish your task.

Oh yes, I understood the way to format using String.format(). It is so convinient but as fate would have had it, my issue is little bigger: I am not using jdk1.5 as I pointed earlier.

Kindly help!

Then you're going to have to reproduce the results yourself.

Take a look at the values to be written into each field, find the longest, and pad the rest in that column to match it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.