0
123,one,two,three,for,five,six

How could I best extract the word after the 3rd occurrence of the , separator? (which would be three in my example.

Probably I'm not the first one doing this and there might be an apache or guava library that provides a static method for this?

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • http://stackoverflow.com/questions/3976616/how-to-find-nth-occurrence-of-character-in-a-string – aioobe Dec 23 '14 at 10:33
  • If you're after *three* rather than the position of the separator char, you would just do .split(",")[3] – aioobe Dec 23 '14 at 10:35

1 Answers1

2

You van simply use .split(",")[3]

wvdz
  • 16,251
  • 4
  • 53
  • 90