• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ascii letters

 
Paolo Dina
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I'm sure something like this (or similar) is defined somewhere. Where? I looked at Character's fields but I found nothing. Any idea?

Thanks
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know about Unicodes??
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there aren't any arrays of lower case letters defined in the API. What there is, is a lot of methods in the java.lang.Character class which you can use to ask whether a character is a letter, number, lowercase, uppercase, etc. As Ankit points out, Java uses Unicode, not ASCII, so some of these questions are a little bit tricky.
 
Paolo Dina
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If I want to print characters from a to z, shoud I define my constant (as in the example) or I can find one already defined? Hope my question makes sense.

Thanks

P.S.
Thanks Ernest, that was the answer I was looking for.
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I can provide a complete code but I think it would be fun if you experiment with it yourself. I would just give you some hints. create a character variable with the value 'a'. Then use the Character.numericValue method along with the ability to assign an int value into a char variable to attain what you want. I hope you would have fun experimenting with the stuff ...
 
Paolo Dina
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Much better if there was a static field to be used out of the box ;-)
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Character#numericValue doesn't do what you think it does. But it is still worthwhile going through the Character class, because it has all sorts of useful isSomething methods.
Don't use 97; you are a computer scientist now. Use 0x61. You can find the ASCII values from Unicode because this PDF is identical to ASCII. Note the values are in hexadecimal.
 
Paul Clapham
Sheriff
Posts: 21116
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And have a look at the Character.UnicodeBlock class -- that might relate to your question. There's a lot in Unicode besides ASCII.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paolo Dina wrote:
Much better if there was a static field to be used out of the box ;-)


Even given that this is what you actually want, you could replace that magic 97 with 'a'. Or replace the whole routine with

"abcdefghijklmnopqrstuvwxyz".toCharArray();

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic