posted 19 years ago
As to your logic, you simply incorrectly assumed the function of getBytes. It doesn't return the number of bytes the string is using, rather it converts the string to something else entirely, which confusingly uses fewer bytes.
thats a nice answer.
>The number of bytes will always be 2 * the number of characters.
>The relationship between ASCII and Unicode is that Unicode creates a much higher number of >possible characters.
yea, some odd looking chars(japanese,arabic ? )
>However, the original numbers still carry over I believe, as such, what was character # 126 in >ASCII is now character # 000126. (That's not technically correct, but if you apply the >principal to binary notation rather than decimal notation, then my statement becomes true. It >just adds zeroes to the front to use up 2 bytes.)
OK,
so tell me in this example , string "123456"
take out first char i.e "1" what do u call it ? ASCII char or Unicode Char ? i assume you will term this char as Unicode with a imaginary padding up leading zeros. right ?
Now here is the crucial point , if you tell "1" is an ASCII char then you will get 6 because ASCII char will take 1 bytes. but if you tell "1" is a Unicode with your imaginary leading zeros ( and also because its java langunage and java language chars are Unicode ) then it will take 2*6=12 bytes.
so, which one i should think about the char "1" . is it a Unicode char or ASCII char
because whole thing depends upon the decision of its status ?
i assume you will call it a unicode char, so there is actually 12 bytes are taken by this string. but we can not show it by programmatically because we can not have such methods.
but i have a method getBytes() in doc, if i use this method this will thik "1" as ASCII char and will give me result accordingly.
am i right ?