0

every one I want to use for the strings like

"Ravi;Dutt;;" 

but when I use split for this string . It gives result like mentioned above. I got an array of size 2. But in my requirement it should be of 3 as one for last two delimiters. Please help me thanks in advance.

aelor
  • 10,892
  • 3
  • 32
  • 48
Ravi Dutt
  • 135
  • 2
  • 4
  • 16
  • I assume you use ; as delimeter? have you tried putting something between the last two ;'s? at this moment, there is no String there, so pretty normal it won't return anything – Stultuske May 21 '14 at 10:56
  • yes Stultuske. But basically my need is to split it in such a way that at first index of array it will be Ravi, Dutt on 2nd index and the third index must be empty only – Ravi Dutt May 21 '14 at 11:05

1 Answers1

2

By default, trailing empty strings (those at the end of the array) are discarded.

If you want to include these as well, try

split(";", -1)
aelor
  • 10,892
  • 3
  • 32
  • 48
  • 1
    But you will end up with two empty Strings at the end. – Alexis C. May 21 '14 at 10:57
  • my need is to split it in such a way that at first index of array it will be Ravi, Dutt on 2nd index and the third index must be empty only. But if I uses your idea it gives size four array it should be 3 – Ravi Dutt May 21 '14 at 11:06