0

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?

2
  • Add a .subtring(1) before your split("#"). Commented May 7, 2020 at 6:12
  • You could also filter out the empty result(s) from split() if that is what is wanted. Commented May 7, 2020 at 6:16

3 Answers 3

1

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("#");
Sign up to request clarification or add additional context in comments.

Comments

1

Remove the first # before splitting

 String[] array = str.replaceFirst("#", "").split("#");

2 Comments

Will it work if the input is a#b#c#d#e? If the given text always begins with # then this work.
@NKR As I interpret the question the syntax is #value for each column
0

The issue can be solved with the regex (?<=\#)(.)

Code:

output.getText("TAG", i).split("(?<=\#)(.)");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.