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:

Timisorean
  • 1,388
  • 7
  • 20
  • 30

1 Answers1

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.

Richard Barker
  • 1,161
  • 2
  • 12
  • 30
  • 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. – angryip Oct 12 '19 at 17:59