Skip to content

Instantly share code, notes, and snippets.

@SriniBlog
Created December 23, 2015 16:05
Show Gist options
  • Save SriniBlog/d950ae2a9d4dc98422b5 to your computer and use it in GitHub Desktop.
Save SriniBlog/d950ae2a9d4dc98422b5 to your computer and use it in GitHub Desktop.
This function is similar to PI Standard Function but it won't throw exception like the standard UDF
public String subStrings(String FieldValue, String startPos, String endPos, Container container) throws StreamTransformationException{
String newFieldValue = "";
try{
int istartPos = Integer.parseInt(startPos);
int iendPos = Integer.parseInt(endPos);
if( startPos.equals("-1") ){ //startPos value is passed as -1 then substring from 0 till the endPos value
newFieldValue = FieldValue.substring(0,iendPos);
}else if ( endPos.equals("-1") ){ //endPos value is passed as -1 then substring from startPos till end
newFieldValue = FieldValue.substring(istartPos);
}else{
newFieldValue = FieldValue.substring(istartPos, iendPos); //This is a normal substring with exception block
}
}catch(Exception ee){
newFieldValue = FieldValue;
}
return newFieldValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment