Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
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-30-2007, 04:21 PM
Member
 
Join Date: Jul 2007
Posts: 41
gabriel is on a distinguished road
how to know the number of bytes
I want to find out number of bytes in a string
how can I do that?
there is a getbyte function in String class, but it returns a Byte array
I want to get the number of bytes occupied by a string.
can you help me?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-30-2007, 07:35 PM
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
This is a more complicated question then it appears. What are you using the value for? The reason is that a Java String object is stored internally as unicode.

You can get the number of bytes by doing the following:
String str = "My name";
int bytes = str.getBytes().length;

But this number depends on the character encoding of my current platform.

There is also the length() method on the String class that will tell you the number of characters in the string.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-06-2007, 07:13 PM
Member
 
Join Date: Jul 2007
Posts: 41
gabriel is on a distinguished road
thanks for your explanation
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
DES algorithm (Read and Write bytes to file) JoaoPe Advanced Java 6 07-29-2008 05:46 PM
The highest number I-Shine Java Applets 3 02-13-2008 07:05 AM
Reading bytes from InputStream Java Tip Java Tips 0 11-25-2007 09:51 PM
How to get next available number from MS access shahjehan Database 3 11-18-2007 09:41 PM
how to know the number of the line simon New To Java 3 08-01-2007 06:59 PM


All times are GMT +3. The time now is 10:56 PM.


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