Since String.split()
works with regular expressions, this snippet:
String s = "str?str?argh";
s.split("r?");
... yields: [, s, t, , ?, s, t, , ?, a, , g, h]
What's the most elegant way to split this String on the r?
sequence so that it produces [st, st, argh]
?
EDIT: I know that I can escape the problematic ?
. The trouble is I don't know the delimiter offhand and I don't feel like working this around by writing an escapeGenericRegex()
function.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…