How to find the position of n-th occurrence of character in a string

Hi,

I have one field that contain several pipes "|" and the pipes are not in a specific position (they can be anywhere). How can I find the position of the 10th occurence of the pipe in this string for each record?

Thanks you in adavance   

Using a Java Snippet node, you can use the following code (will return a value of -1, in case there is no n-th match of the character):

// input
String string = "1|23|4567|890|234|956780|123496|923|12|4|5567|3343|0";
int n = 10;
char ch = '|';

// result
int idx = -1;

for (int i = 0; i < n; i++) {
	idx = string.indexOf(ch, idx + 1);
	if (idx == -1) {
		break;
	}
}

System.out.println("index of " + n + "th " + ch + " = " + idx);

-- Philipp

Thank you very much! It works perfectly...