1
我需要能够将“x.y”这样的单个字符串拆分为大小为2的数组,其中“。”发生,所以数组看起来像[“x”,“y”]。我试过的是:拆分“。”。发生
String word = "hello.world";
String[] split = word.split(".")
return split.length == 2;
但这似乎只是返回一个空数组(false)。我会如何去做这件事?谢谢。
我需要能够将“x.y”这样的单个字符串拆分为大小为2的数组,其中“。”发生,所以数组看起来像[“x”,“y”]。我试过的是:拆分“。”。发生
String word = "hello.world";
String[] split = word.split(".")
return split.length == 2;
但这似乎只是返回一个空数组(false)。我会如何去做这件事?谢谢。
Repalce这
String[] split = word.split(".")
与
String[] split = word.split("\\.")
.
(点)的,所以你需要逃避它,如果你想用它作为文字拆分正则表达式中有特殊的含义。
['.dot有一个特殊的含义。](http://stackoverflow.com/questions/13989640/regular-expression-to-match-a-dot) – sam
啊,这么愚蠢的疏忽。谢谢! –