on 03-17-2008 2:37 PM
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.
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--
D_0062 Thats it...
Reward Points if it is really useful to you..
Thanks,
Satya Kumar...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sravan,
As suggested above, the ROUND function in the Arithmetic functions suffices your requirement, without going in for UDF.
Regards,
Lavita.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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......
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
here is the coding for you UDF:
return YourString.replaceAll("^0*","");
Thats all
Regards Mario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
In Arthmetic - Round function make use of it.
Regards
Agasthuri Doss
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.