[英]split up data with java split() make empty data of first array
DB has like this data for hashtag in string type DB 有这样的数据,用于字符串类型的主题标签
#a#b#c#d#e
with this data, I want split each tag有了这些数据,我想拆分每个标签
so I code this所以我编码这个
String tagToArray[] = output.getText("TAG", i).split("#");
but the result is但结果是
tagToArray[, a, b, c, d, e]
I want to remove first empty data what is the right way to splay data of hashtag?我想删除第一个空数据什么是显示标签数据的正确方法?
This extra empty string produce for first #
.这个额外的空字符串产生第一个#
。
So, you can replace the first character if it is #
then split.所以,你可以替换第一个字符,如果它是#
然后拆分。
String tagToArray[] = output.getText("TAG", i).replaceFirst("^#", "").split("#");
Remove the first # before splitting拆分前删除第一个#
String[] array = str.replaceFirst("#", "").split("#");
The issue can be solved with the regex (?<=\#)(.)
可以使用正则表达式(?<=\#)(.)
解决该问题
Code:代码:
output.getText("TAG", i).split("(?<=\#)(.)");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.