0

I have string content and need to split into an array of tokens, but one of the tokens as a result is "", which can result in multiple tokens like "" and I need to avoid them by Regexp.

I try use the Regexp like the print but he do not remove my problem.

Node content example:

Regexp and the result:

5
  • can you show some code and paste the string data that is relevant? Commented Oct 12, 2019 at 14:03
  • i put the image on imgur, i am new on stack and i dont no how to use code rules correctly, sory. Commented Oct 12, 2019 at 14:25
  • I could simply remove the token using "" array.remove(""), but in my application that would be a high computational cost i think. Commented Oct 12, 2019 at 14:29
  • Don(t post links to images of your code. Post the code itself, as text, properly formatted, in the question itself. Commented Oct 12, 2019 at 15:12
  • This is probably a duplicate of stackoverflow.com/questions/3085539/… Commented Oct 12, 2019 at 17:59

1 Answer 1

0

You are splitting your string on spaces (among various other characters).

You'd be better off if(node.equals("")){// ignore it or remove it} because whatever you split your string on, you will always have to worry about empty results because your split character could be anywhere in the string. Calling trim on your string before you split it will get rid of all that extra leading and trailing space and, because it's spaces you're splitting on, get rid of those pesky empty values; which from what I can see in your question, is exactly what's going on.

Sign up to request clarification or add additional context in comments.

1 Comment

This is incorrect. You cannot compare strings in java with 3 ===. You have to use a .equals method. But other than that, I agree, the problem should be simplified and not alien regex code.

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.