on 08-30-2008 12:45 PM
Dear All,
I have to create a user-defined function that would accept the input value and modify it such that the leadign 0's are truncated.
The input value from the source field can be a integer or alpha numeric.
Please suggest some ways to write the code.
Regards,
Rajendra
HI,
Develop UDF using below code,
String stringWithoutZeros = a.replaceFirst("^0+", "");
return(stringWithoutZeros);
I hope your problem will be sort out
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
We have used following code in our project for the same thing.
public void removeZeros(String[] a,ResultList result,Container container){
{
String body="";
for(int j=0;j<a.length;j++)
{
body=a[j];
for(int i=0;i<a[j].length();i++)
{
if(body.substring(0,1).equals("0"))
{
body= body.substring(1,body.length());
}
}
result.addValue(body);
}
}
with regards,
Ravi Siddam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
No need for a UDF. This can be done through graphical mapping even.
Source--------->
div(Arithmetic function)---->target
constant[1]--->
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try this:
for RemoveLeadingZeros
int value = Integer.parseInt(str);
String str1 = Integer.toString(value) ;
return str1;
Regards,
Nithiyanandam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try this:
public String truncate(String a, Container container)
{
if (a.length() > 0)
{
String b = a.replaceAll("^0*", " ");
return b;
}
else
{
return a;
}
}
source field -> UDF -> target field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To remove leading zeros
public String removeLeadingZeros(String str) {
if (str == null) {
return null;
}
char[] chars = str.toCharArray();
int index = 0;
for (; index < str.length; index++) {
if (chars[index] != '0') {
break;
}
}
return (index == 0) ? str : str.substring(index);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use arithmetic function 'mul' and multiply the field with 1, it wud remove the leading zeroes.
if it is coming as string - cast it to an integer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A guy started a Wiki page entry with useful UDF codes:
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/javaFunctionsin+XI
Regards
Stefan
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.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.