The moose likes HTML, CSS and JavaScript and the fly likes Netbeans and Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Netbeans and Strings" Watch "Netbeans and Strings" New topic

Netbeans and Strings

Peter Matthews

Joined: Nov 07, 2005
Posts: 21
Hi All,

Just started working with Netbeans and encountered a problem when trying to format a String. I'm wanting to include more than one space between the variables as shown below:

public String toString() {
String s = ref + " " + seller + " " + description + " " + bedrooms + " " + "�"+price;

return s;

But everything I try, it displays only one space between each variable. Even if I use the "\t" it doesnt make a difference. Its just that I want to align them to column headings, so its quite frustrating!

Is there an option I need to change in Netbeans, or am I being dumb!?

Thanks for any help,

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Hi Peter,

The fact that you're using NetBeans shouldn't matter. What matters more is where the output is going. If this is in a JSP or servlet, then no matter how much space you use, the browser is going to squash it down to one. If it's going to the command line, whether or not \t characters are meaningful depends on the terminal program that you're running in. So tell us about the environment this code is running in, and we may be able to tell you what to do.

[Jess in Action][AskingGoodQuestions]
Peter Matthews

Joined: Nov 07, 2005
Posts: 21
Hi Ernest,

Its being used by a servlet and then being passed to a JSP... is there anyway of getting around this problem?


Naveen K Garg
Ranch Hand

Joined: Nov 28, 2005
Posts: 105
Hi Peter,

Try using HTML Entities in your code. For example to print a space on your JSP page use  

So in your code it will be as follows:

String s = ref + "  " + seller + "  " + description + "  " + bedrooms + "  " + "�"+price;

Search on google for more information on HTML Entities.

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
This problem is not related to Java, but to HTML. Moving to our HTML forum.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: Netbeans and Strings
It's not a secret anymore!