【发布时间】:2013-10-21 19:42:00
【问题描述】:
我试图将一个字符串拆分为一个字符串数组,问题是.split() 也返回一个空元素。 ("test").split 将返回 ["","t","e","s","t"]。
这个问题Split string into array of character strings的解决方案解决了这个问题(使用.split("(?!^)"))。
但是我仍然无法理解为什么会这样,而且我不会使用一段我无法理解的代码,因为它可以完成工作。
我已经阅读了这两页 http://www.regular-expressions.info/lookaround.html 和 http://ocpsoft.org/opensource/guide-to-regular-expressions-in-java-part-2/ 关于负前瞻的内容,但仍然无法理解。有人可以澄清一下吗?
【问题讨论】:
-
为什么不使用
String#toCharArray(); -
程序中使用的其中一个类中有一个属性被定义为String,该属性用于与输入的字母进行比较。