• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cut out a Specific Portion of a Random String

 
Lluvian Brown
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I want to know if there is a way to cut out a string in Java. Lets say I have three string below:

Test string number, test this out, hi: My name is John, test this out here
Another test string, testing this out for me, hi: My name is Frank, done here testing
Last test string, testing cut strings, hi: My name is Jeff, last test done

I want the ability to search for the key words "hi:" and when I find it I need to cut out hi: and everything until the first ",". My program that I am experimenting with will be done if I am able to complete this task.

This helps we with certain log files that I search through.

-Thanks
 
Winston Gutkowski
Bartender
Pie
Posts: 10506
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lluvian Brown wrote:I want to know if there is a way to cut out a string in Java.

I recommend you study the String class documentation (java.lang.String (←click)), because there are too many methods to go into detail here.

I would suggest that you pay particular attention to the indexOf() and substring() methods though.

HIH

Winston
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, before you write a line of code, figure out how YOU would tell someone (say a 10 year old child) how do do what you need done. Use English, not java. Use simple phrases like:

Look at each string, one at a time,
In a given string, look for the word "Hi" - but don't worry about the case.
Make sure you don't find "hi" inside a word...like "Ohio"
Look for the first comma after the word "hi"

etc..

 
Lluvian Brown
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out thanks.

I am coming from another language and I am not familiar with the built in methods. I have not used Java since my first programming course in college.
 
Lluvian Brown
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for everything guys!

Just in case someone needs help with this here is an example:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic