• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Finding last index of space

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

 
Rancher
Posts: 1173
16
  • 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!