I want to split a string with "?" as the delimitter.
str.split("?")[0] fails.
I want to split a string with "?" as the delimitter.
str.split("?")[0] fails.
The argument to the "split" method must be a regular expression, and the '?' character has special meaning in regular expressions so you have to escape it. That's done by adding a backslash before it in the regexp. However, since the regexp is being supplied by way of a Java String, it requires two backslashes instead so as to get an actual backslash character into the regexp:
str.split( "\\?" )[0];