title: Java: extract a value from a string based on delimiters
body: <p>I have a string <code>"abc|def|123|456|xxx"</code>. I need to extract a subset of the string based on the position of the delimiter. The logic is to use the known delimiter <code>"|"</code> and selecting the 2nd field of the <code>"|"</code> delimiter.</p>
  
  <p>A function e.g. like this would suffice.</p>
  
  <p>syntax: <code>function.name(string,delimiter,field count)</code></p>
  
  <p>example 1: <code>function.name("abc|def|123|456|xxx","|",2)</code></p>
  
  <p>Answer: "def"</p>
  
  <p>example 2: <code>function.name("abc|def|123|456|xxx","|",4)</code></p>
  
  <p>Answer: "456"</p>