how do you split a string and get the sentence only after the question mark. For example say you have the line : hello?myNameIs...
how could you only get what's after the question mark
many thanks
Asked
Active
Viewed 40 times
-3

Nick Low
- 13
- 4
-
What have you already tried? – AntonH Dec 06 '17 at 17:34
-
This `(?<=\?).*`? – ctwheels Dec 06 '17 at 17:36
-
Possible duplicate of [Getting the text that follows after the regex match](https://stackoverflow.com/questions/5006716/getting-the-text-that-follows-after-the-regex-match) – ctwheels Dec 06 '17 at 17:36
2 Answers
0
If all your use cases will be similar to the simple example you've stated, you could use a simple split.
The code:
String delim = "\\?";
String s = "hello?myNameIs";
String token[] = s.split(delim);
System.out.println(token[1]);
Gives the output:
myNameIs
Of course, you can tinker with it to solve your specific problems.

Joseph Ryle
- 129
- 5