View Single Post
  #2 (permalink)  
Old 07-30-2007, 07:35 PM
brianhks brianhks is offline
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.
Reply With Quote