Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-16-2007, 07:01 PM
Member
 
Join Date: Jul 2007
Posts: 26
paul is on a distinguished road
it's possible format data in java?
In java, I know it's possible to format words or numbers. An example would be
Code:
System.out.printf("%15s\n", word);
Which would format whatever the value of word in a space with size 15.

Somewhere I read it's possible to do the same if you are returning a value, but did not provide any examples of it. I tried:

Code:
return %15s\n,word;
ovbiusly I'm trying to return "word", can I format it while I return it?

That doesn't work, as I get illegal start of expression as an error.
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 06:10 AM
Member
 
Join Date: Jul 2007
Posts: 39
coco is on a distinguished road
Not exactly. It doesn't "return" it at all, it just sends it to the out stream using printf...

If you really needed to format a string you could do so through the string
utilities. For example, substring should be able to cut off the part of the string you want.

String (Java 2 Platform SE v1.4.2)

This means however that you will have to check to see if the string is too short. If you don't you'll get an outofbounds exception. So just check the length, if it's less then what you want to crop it to, just return it, else, crop it with substring and return it.
Greetings.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DateField in format : HH:mm:ss:ms gibsonsydsa CLDC and MIDP 4 03-10-2008 08:46 AM
Timestamp in SQL format Java Tip Java Tips 0 02-10-2008 12:37 PM
Is there any utility that reads TimeZone data and display it in Human readable format Santhosh Advanced Java 0 11-06-2007 03:20 PM
Code format Eric XML 1 07-06-2007 08:44 AM
Code format Eric XML 1 07-06-2007 08:42 AM


All times are GMT +3. The time now is 10:58 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org