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

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -