Reputation: 9
DB has like this data for hashtag in string type
#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?
Upvotes: 0
Views: 61
Reputation: 1
The issue can be solved with the regex (?<=\#)(.)
Code:
output.getText("TAG", i).split("(?<=\#)(.)");
Upvotes: 0
Reputation: 18440
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("#");
Upvotes: 1
Reputation: 51973
Remove the first # before splitting
String[] array = str.replaceFirst("#", "").split("#");
Upvotes: 1