java - Finding the nth string in a delimited string -


does have idea how find n-th field (string) in delimited string delimiters (separator) either single char or several chars.

for instance,

string = "one*two*three"  separator = "*" 

and syntax user-defined function findnthfield(string,separator,position)

so position 3 return three

the separator in use chr(13).

this has run on android , should efficient.

any suggestions appreciated.

something perhaps?

public string findnthfield(string string, string separator, int position) {     string[] splits = string.split(separator);     if (splits.length < position) {         return null;     }      return splits[position - 1]; } 

obviously, separator must regex string , didn't null check(s).


Comments

Popular posts from this blog

SAP Web Service from .NET via WCF -

Optimized Line drawing in QT -

datetime - str to time in python -