0

I want a String[] that shows this:

Value1: [0, 0, 0, 0, 0, 0, 0, 1]

But when I use String[] b1 = sByte.split("");, I get

Value1: [, 0, 0, 0, 0, 0, 0, 0, 1]

That extra position isn't supposed to be there. Is there any way to remove it?

  • What language is this? – Andrew May 22 '14 at 16:48
  • 8
    what is the content of `sByte` – njzk2 May 22 '14 at 16:51
  • @njzk2 probably a set of bits saved as string, something like `"00000001"` – A4L May 22 '14 at 16:54
  • 3
    [here is a similar question](http://stackoverflow.com/q/22718096/1113392) – A4L May 22 '14 at 16:57
  • 2
    Do you really need to do it with do it with regex? Why not just use `sByte.toCharArray()` and get a `char[]` as result, if those are supposed to be bit values, this would be more handy to work with (comparison with 0 and 1 using == operator)... – A4L May 22 '14 at 17:04

1 Answers1

0

You can split it on a location that is both preceded by and followed by any character:

String[] b1 = sByte.split("(?<=[\\s\\S])(?=[\\s\\S])");
The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75