-3

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

Nick Low
  • 13
  • 4

2 Answers2

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
0

try this one

String sArray[]  = src.split(Pattern.quote("?"));
slawek
  • 328
  • 1
  • 10