• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Find the last character in a srting.

 
Alec Porter
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I' trying to find out how do you know how many characters are in a string. Because to use getChars you have to know before hand how many characters you want to end at.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked the javadoc for the String class? (and please proof-read your posts -- "srting"?)
 
Mina Daoud
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java API docs will answer your question. You can find it in this link http://download.oracle.com/javase/6/docs/api/
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure there is an easier way to do it than use getChars.
 
Java Reni
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can try:

 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java Reni wrote:you can try:


How would you find the last character in a String with lastIndexOf(..) ??
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4116
195
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Java Reni", please check your private messages regarding an important administrative matter.
 
Bobby Smallman
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want to find the *cough* length *cough* of a String huh..... I wonder if the API has information about how to find the *cough* length *cough*


Welcome to Java Ranch!

 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't forget a method to get the char at a specific position. However, what you should never forget are two cases: a) the string is empty (i.e. there is no last character), and b) the string reference is null (i.e. there is no string at all).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic