aspose file tools*
The moose likes Beginning Java and the fly likes Stringbuilder insight Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Stringbuilder insight" Watch "Stringbuilder insight" New topic
Author

Stringbuilder insight

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

This code snippet gives me the result of StringBuilder.codePointAt() for numbers 0 to 9:



However, whilst my output displays numeric codes, an article on Wikipedia, shows different values , any idea what the codePointAt() is meant to retrieve, other than the Unicode character?

0: 73
1: 32
2: 119
3: 97
4: 110
5: 116
6: 32
7: 116
8: 104
9: 101


NOTE to administrator: I got a complaint from the forum spellchecker because I was trying to illustrate what the unicode values on the articles included, for example "you" and a numeric value, which is misleading, because it is common for a developer to quote standards and code.


Jon
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Why are you using Wikipedia rather than the Unicode website? What difference do you see? You haven't said what the input is. If we don't know the input, we shan't know whether there is any difference between the code points and chars.

If you want to post the letter U put that bit inside code tags.
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

It's not hard to copy and paste, even though unfortunately it does not work here, however, values for 0 to 9 return integers that do not seem related to Unicode characters.
If you want to post the letter U put that bit inside code tags.

It's not code it's English..


Output
0: 49
1: 50
2: 51
3: 52
4: 53
5: 54
6: 55
7: 56
8: 57
9: 48



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Nothing wrong with that. You are printing '1' against '0' and '1' is 0x31. So it prints "49". Absolutely correct. Exactly the same value as the Unicode value for '1'.

Remember the Unicode website shows the numbers in hex and you are printing them in decimal. Try this printing instruction:And the reason for using code tags is that you are quoting your output and the checking for the letter U is disabled inside code tags.
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Campbell Ritchie wrote:Nothing wrong with that. You are printing '1' against '0' and '1' is 0x31. So it prints "49". Absolutely correct. Exactly the same value as the Unicode value for '1'.

Remember the Unicode website shows the numbers in hex and you are printing them in decimal. Try this printing instruction:And the reason for using code tags is that you are quoting your output and the checking for the letter U is disabled inside code tags.


So it's hex, converted to base-10, interesting notation, which has something to do with the way computers store binary digits in registers that are in multiples of 8 (e.g. 16, 32, 64 bit).

Whilst helpful, I couldn't quite figure out the printf line, since the compiler does not like compiling a cast to a (char) value, and, I couldn't quite understand the first parameter, it's not documented in my book (p.67-68).


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
That is peculiar; the first tag is in my copy (older edition, page 61). And you should have read my post properly; I specifically declared cp as an int so you can cast it. The width and 0 options are clearly shown in the book too.

You should always look in the API documentation in preference to a book.
 
Don't get me started about those stupid light bulbs.
 
subject: Stringbuilder insight