• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get substring in string line entry?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;"");
test1.txt=left(right(line;"");"")
I am newbie to java, any helps are appreciative.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic