How to select a section of a string from 2 specific points when you cannot use IndexOf in Java -


i'm writing program school project make array , synonyms text file we've been given creating object called word stores word , synonym , making class called wordarray.

wordarray takes words , synonyms text file , stores them in array word objects.

then have method called search() parameter used find either words partially match parameter.

for example: if parameter rep, method return words repressed , represent), or 1 word same parameter. if there multiple words match parameter, method include number (starting @ 1) , place before word.

now need have code in main class takes wordarray (a) , performs search() method based on string user inputs.

i show user words have been found based on input.

if there 1 word returned, stores word string, if there more; ask user input number corresponds number included before word in list of strings.

my problem is, want store word in word string, , last line of code shows have done far. in format:

word = list.substring(list.indexof(j), *the character after end of word*);

the issue i'm not sure how that, can't use lastindexof or indexof, because word might in middle of list of multiple words, in case wouldn't work.

are there string methods use?

my code far below:

string temp = joptionpane.showinputdialog("input word or part of one:");    string list = a.search(temp);    string word = "";    system.out.println(list);    if (list.charat(0) != '1')    {        word = list;    }    else    {      string j = joptionpane.showinputdialog("type number of word you'd like:");      word = list.substring(list.indexof(j));    }   

no validation here , assuming list contains something:

string temp = joptionpane.showinputdialog("input word or part of one:"); //pp string list = a.search(temp); system.out.println(list); //"1apple 2application" string input = ""; if(list.contains(" ")) //more 1 word ??? {     input = joptionpane.showinputdialog("type number of word you'd like:"); } string number = input; string result = arrays.aslist(list.split(" ")).stream()     .filter(e -> e.startswith(number))     .findfirst()     .get();  system.out.println(result); //1apple || 2application 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -