aspose file tools*
The moose likes Beginning Java and the fly likes Find the last character in a srting. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Find the last character in a srting." Watch "Find the last character in a srting." New topic
Author

Find the last character in a srting.

Alec Porter
Greenhorn

Joined: Sep 05, 2010
Posts: 29
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

Joined: Jan 10, 2002
Posts: 61204
    
  66

Have you checked the javadoc for the String class? (and please proof-read your posts -- "srting"?)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mina Daoud
Ranch Hand

Joined: Sep 24, 2010
Posts: 88
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

Joined: Oct 13, 2005
Posts: 38818
    
  23
I am sure there is an easier way to do it than use getChars.
Java Reni
Greenhorn

Joined: Oct 01, 2010
Posts: 1
you can try:

Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Java Reni wrote:you can try:


How would you find the last character in a String with lastIndexOf(..) ??


Regards, Rene Larsen
Dropbox Invite
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3094
    
  40

"Java Reni", please check your private messages regarding an important administrative matter.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Bobby Smallman
Ranch Hand

Joined: Sep 09, 2010
Posts: 107
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!


Everyday in every way, we get a little better.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

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).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Find the last character in a srting.