Sunday, June 16, 2013

Talend Equivalent for Index Function in Datastage

 
package routines;

public class UserString {

	public static int Index(String string, String substring, Integer instance) {
	    	int index = -1;
	    	if (string == null) {
	    		return 0;
	    	}
	    	if (substring == null) {
	    		return 0;
	    	}
	    	if (substring.equals("")) {
	    		return 1;
	    	}
	    	if (instance == null) {
	    		throw new UnsupportedOperationException("Instance is supposed to be NOT NULL!!");
	    	}
	    	if (!string.contains(substring)) {
	    		return 0;
	    	}
	    	
	    	index = string.indexOf(substring, 0);
	    	
	    	while (--instance > 0 && index != -1) {
	    		index = string.indexOf(substring, index + 1);
	    	}
	    	    	
	    	return ++index;
	}
}

0 comments:

Post a Comment

Contact Form

Name

Email *

Message *

The Insane Techie - Android App

Launched an android app for the blog on 07th June 2016. Get it from google play store... Tips for using the app Use in landscape mo...