Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding last index of space  RSS feed

 
Divya Guttikonda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have some text say "javaranch big moose saloon".I am trying to use the method like this.
int index = text.lastIndexOf('');//Here in the paranthesis i want to give the empty space.I tried '\0' but it is not working.How should i be able to identify the space between say "javaranch" and "big".I want the space index.Please help.
 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i understand you correct, you want to get the index of a given space? You could try something like:

 
Ryan McGuire
Ranch Hand
Posts: 1142
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Divya Guttikonda:
Hi

I have some text say "javaranch big moose saloon".I am trying to use the method like this.
int index = text.lastIndexOf('');//Here in the paranthesis i want to give the empty space.I tried '\0' but it is not working.How should i be able to identify the space between say "javaranch" and "big".I want the space index.Please help.


If you're looking for the index of the space between "javaranch" and "big", use indexOf(String). If you want the index of the LAST space, i.e. the one between "moose" and "saloon", use lastIndexOf(String).

 
Divya Guttikonda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes..i got it.Thankyou guys for your replies.I tried with lastIndexOf(" ");
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!