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?
Printable View
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?
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.
thanks for your explanation