Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Find the last character in a srting.

 
Alec Porter
Greenhorn
Posts: 29
  • 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: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
  • 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
Posts: 48406
56
  • 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
  • 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
  • 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: 4262
229
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • 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
  • 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: 20495
54
Chrome Eclipse IDE Java Windows
  • 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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic