This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Searching for a specific word in a string  RSS feed

 
Abhijith Sugunan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey can anyone tell me how to search for a specific word in a string and store what ever comes after that string....
 
Paul Clapham
Sheriff
Posts: 22472
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the API documentation for the String class. You need a method to find the location of the specific word, and a method to extract part of the string given the position of the starting characters. Both methods are documented there.
 
Naishadh Parmar
Ranch Hand
Posts: 95
C++ Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the substring method of String class.

Suppose you have a string- "My name is Abhijith". You want to find the word "name", you type this:

Note: The first index while doing substring is "0" and not "1"
 
Paul Clapham
Sheriff
Posts: 22472
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naisadh, one of our rules here is LetThemDoTheirOwnHomework (follow the link to our FAQ entry).

However I'm not going to edit the code out of your post because (a) it doesn't do what Abhijith's original post asked, and (b) it doesn't even do a good job of what it does try to do. But it's a good starting point, and people can point out things which could improve it in the direction of answering the original post.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!