File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Cut out a Specific Portion of a Random String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cut out a Specific Portion of a Random String" Watch "Cut out a Specific Portion of a Random String" New topic
Author

Cut out a Specific Portion of a Random String

Lluvian Brown
Greenhorn

Joined: Apr 16, 2013
Posts: 4
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

Joined: Mar 17, 2011
Posts: 7064
    
  16

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

Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

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


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Lluvian Brown
Greenhorn

Joined: Apr 16, 2013
Posts: 4
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

Joined: Apr 16, 2013
Posts: 4
Thanks for everything guys!

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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cut out a Specific Portion of a Random String
 
Similar Threads
Which pattern is best suitable for this prob.
Sql Where clause and/or issues
Functional testing of webpage
Tab character question
Encoding and Decoding