I need to isolate a word that starts with a hashtag (#) from a string of user input. For example if the user enters "Hi how #are you today" i need the program to print out "#are".
My thought process was to try to isolate the substring from the index of the # to the next space, but I do not know how to get it to recognize the index of the next space instead of just the first space in the string. So my code for this action looks a little like this right now:
tweet = keyboard.nextLine();
int pos = tweet.indexOf("#");
String hashtag = tweet.substring(pos, " ");
System.out.println("Hashtag: " + hashtag);
ANY advice would be helpful. Also I have not learned about loops or arrays yet so if there is anyway to do this without them that would be great!