Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有使用 Guavas Splitter 拆分字符串并保留分隔符而不使用正则表达式的简单方法?
就像是
String string = "1+2-3*40"; Splitter splitter = Splitter.on(CharMatcher.DIGIT.negate()).retainDelimiters();
这给了
[1, +, 2, -, 3, *, 40]
我知道 Splitter.onpattern() 但这需要我给它一个正则表达式(但这就是我试图避免的)。
我认为现在不能在 Guava 中完成,但您可以提交功能请求。顺便说一句,输出是"1+3**2"什么?我认为这里的模式是明确的。
"1+3**2"