我该如何分割点的字符串? [英] How can I split a String of dots?
本文介绍了我该如何分割点的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串,它看起来像这样-...
我想将它分成4个简单的字符串 -
,
,
,
我怎样才能做到这一点?
I have a String which looks like this "-..."
I would like to split it into 4 simple Strings "-"
"."
"."
"."
How can I achieve this?
String.split(。)
和 String.toCharArray()
没有工作。
推荐答案
使用空字符串作为分隔符分割:
Split using the empty string as seperator:
"-...".split("")
编辑:
不幸的是这增加了一个空字符串作为Java 7中(在Java中8,它工作正常)的第一个元素。
Unfortunately this adds a empty string as the first element in java 7. (In java 8 it works fine).
法拉杰Farook的解决方案在Java 7和Java 8部作品。
Faraj Farook's solution works in java 7 and java 8.
这篇关于我该如何分割点的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文