cancel
Showing results for 
Search instead for 
Did you mean: 

remove leading zero's

Former Member
0 Kudos

hi to all,

what is the process to remove the leading zero's of a field value (ex : 00000123) ,will sending data from source to target in file to file scenario ,which function we have to use ,

thanx in advance ,

kumar.

Accepted Solutions (0)

Answers (11)

Answers (11)

former_member556603
Active Contributor
0 Kudos

Hi Sravan,

This one is Simple...

No need to write User Defined Function For this..

Go to Message Mapping...In Functions Click Arithmetic...In Arithmetic Select (abs) Function..

For Example Source Is DOCNUM and Tagget is D_0062 (unique message ref)

Mapped Like this ..

DOCNUM--


abs--


D_0062 Thats it...

Reward Points if it is really useful to you..

Thanks,

Satya Kumar...

Former Member
0 Kudos

Hi sravan,

paste this below code:

public String removeLeadingZeros(String num,Container container){

int i;

for(i=0;i<num.length();i++)

if(num.charAt(i)!='0') break;

return num.substring(i, num.length());

Please reward points if helpful.

Regards,

Sankar

Former Member
0 Kudos

Hi Sravan,

As suggested above, the ROUND function in the Arithmetic functions suffices your requirement, without going in for UDF.

Regards,

Lavita.

Former Member
0 Kudos

hi,

i don't why every body is going for UDFS if there is a standard function available in XI,you can achive it with ROUND function.........

reward points if answers found helpfull......

aashish_sinha
Active Contributor
0 Kudos

HI,

yOU CAN USE abs and round functions also from arithmetic in message mapping. will give same results.

Use this UDF code,

public String remLeadZeros(String a,Container container){

String b = a.replaceFirst("^0+", "");

return b;

}

Hope this will help you.

Regards

Aashish Sinha

PS : reward points if helpful

Former Member
0 Kudos

Hi Sravan,

You can solve thos using a UDF(Generic one).Below is the code for the same.

public static String lTrim(String text, String trimCharacter) {

if (text == null) {

throw new IllegalArgumentException("Text to be trimmed is null");

}

if (trimCharacter != null && trimCharacter.length() > 1) {

throw new IllegalArgumentException(

"Trim character length should not be greater than 1");

}

String returnStr = text;

int lengthOfText = text.length();

// if trimCharacter contains null or empty then initialise it with

// whitespace

if ("".equals(trimCharacter) || trimCharacter == null) {

trimCharacter = " ";

}

// check if text begins with trimCharacter

if (text.startsWith(trimCharacter)) {

boolean textContainOnlyTrimChar = true;

for (int j = 0; j < lengthOfText; j++) {

/*

  • search for first occurance of any character other than

  • trimCharacter and once found substring then string from that

  • position

*/

if (!trimCharacter.equals(String.valueOf(text.charAt(j)))) {

returnStr = text.substring(j, lengthOfText);

textContainOnlyTrimChar = false;// found a character which

// is not equal to the trim

// character

break;

}

}

// all the characters in the string are equal to the trimcharacter

if (textContainOnlyTrimChar) {

returnStr = "";

}

}

return returnStr;

}

Here in the above UDF your first input will be the feild(ex. 00000123) and your second will the field you want to trim(ex. "0","1" etc..,).Thus this UDF can be more generic.

Please let me know if u need any furthur information.

Thanks,

Bhargav.

Note:Award points if found useful

Former Member
0 Kudos

Hi Sravan,

I had the same requirement and i ahve used FormatNumber with just single # and it removes all the leading zeros and you can also use Round function.

You can try both Round and FormatNumber with single #.

Thanks,

Srini

Former Member
0 Kudos

Hi,

here is the coding for you UDF:

return YourString.replaceAll("^0*","");

Thats all

Regards Mario

Former Member
0 Kudos

Hi,

This may be Usefull

Regards

Seshagiri

Edited by: N V Seshagiri on Mar 17, 2008 3:46 PM

agasthuri_doss
Active Contributor
0 Kudos

Hi,

In Arthmetic - Round function make use of it.

Regards

Agasthuri Doss

Former Member
0 Kudos

Hi Sarvan,

create a UDF for it...........in the UDF take the source string as input............by indexOf function in JAVA, find index of zero in the input string............if zero is not at first postion then return string as such......otherwise create a new string containing all the characters after the leading zeros...........

Regards,

Rajeev Gupta

Edited by: RAJEEV GUPTA on Mar 17, 2008 3:39 PM