Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Netbeans and Strings

 
Peter Matthews
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,

Pete
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Matthews
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest,

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

Thanks,

Pete
 
Naveen K Garg
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards
Naveen
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This problem is not related to Java, but to HTML. Moving to our HTML forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic