This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get ASCII Value  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1775
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am needing to encrypt a string. I want to get the value of each character, perform a function on it, left pad the result with zeros by to get total of 3 digits then concatenate the results into a single string.

How do I get the ASCII value of each character?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get the characters in the string by using charAt(index). Then simply cast the char to an int.

Note: Characters in Java are 16-bit Unicode characters (not just ASCII characters).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!