Skip to Content

Pad number of hyphen(_) on left side based on length of field value in PI

Hi Experts,

I have requirement like if the length of the field value is less than 11 then it should be pad with that many number of white spaces.

for example:

948243 --> -----948243 [since input length is 6 the output contains 5 hyphens]

Thanks!

Add comment
10|10000 characters needed characters exceeded

  • Hello,

    Use FormatNumber from Arithmetic functions in your Message mapping and provide 11 hyphens in number format. So that you will get your required output.

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Feb 06 at 08:06 PM

    You can create a simple UDF to insert the values

    UDF Code

    StringBuffer sb   = new StringBuffer(inputData);
    
    int strLengthDiff = maxLength-inputData.length();
    
    
    if(strLengthDiff > 0){
    	
    	for(int i=0;i<strLengthDiff;i++){
    						
    		sb.insert(0,charData);
    										
    	}
    	
    	return sb.toString();
    
    
    }else{
    	
    	return inputData;
    	
    }
    
    Add comment
    10|10000 characters needed characters exceeded