类似于:How to split String with some separator but without removing that separator in Java?
我需要使用“Hello World”并获得[“Hello”,“”,“World”]
最佳答案
您可以使用正则表达式,尽管这可能是一个过大的技巧:
StringCollection resultList = new StringCollection();
Regex regexObj = new Regex(@"(?:\b\w+\b|\s)");
Match matchResult = regexObj.Match(subjectString);
while (matchResult.Success) {
resultList.Add(matchResult.Value);
matchResult = matchResult.NextMatch();
}