Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes How to get substring in string line entry? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get substring in string line entry?" Watch "How to get substring in string line entry?" New topic

How to get substring in string line entry?

Peter Cong

Joined: Nov 21, 2009
Posts: 16
The input string is like this:
When user enter the following line,
change test1.txt test2.txt ...
I want to get the word: change and only need the first file name: test1.txt, regardless the test2.txt or others.
In other words, for this case of input, I only need "change" and "test1.txt" , no rests.
the "change" string as a command, it may change to "get", "put" etc. but there is one space between it with the file name string.
Ideally, I look for some java command like,
String line = fromUser.readLine();
change = left(line;"");
I am newbie to java, any helps are appreciative.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19651

Not really socket / Internet protocol related; this is a general Java question. Moving to Java in General.

And for the record, check out the String.split, String indexOf and String.substring methods.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: How to get substring in string line entry?
Similar Threads
Comparing two huge files
What name to use to save files; what classes are allowed?
instanceof question?