on 02-15-2011 9:07 PM
Hi,
I need to do get only the last 8 charters of the string, how can I do this? please help
Eg:
Input
1234567890
output
34567890
or
Input
1234567890456
output
67890456
Hi,
Just write this simple UDF:
This UDF takes a single String array as input(say s[ ]) and it has a single ResultList item as output(say result)
CODE IS AS FOLLOWS:
String k=null;
k=s[0].substring((s[0].length()-8),(s[0].length()));
result.addValue(k);
Pass the output of this UDF to the target field. That's it. I have tested this code. It was successful.
Thanks
Biswajit
Edited by: 007biswa on Feb 16, 2011 1:15 PM
Edited by: 007biswa on Feb 16, 2011 1:15 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
you have two standard functions:
1 substring(start position, size) -> return a "size" length substring from your start position
2 length -> return the size of a string
So you wan really substrin(length-7, 😎
+--------+ +-----+
inputTag --> | length | --> | | +-----------+
+--------+ | add | --> | |
7 --> | | | |
+-----+ | substring | --> outputTag
| |
8 --> | |
+-----------+
Let me know if you need more details.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Tested this simple udf and works as per the need
Title: lastEightCharacters
Execution type: Single values
public String lastEightCharacters(String var1, Container container) throws StreamTransformationException{
int length = var1.length();
String str = var1.substring(length-8,length);
return str;
}
Edited by: Baskar Gopal on Feb 15, 2011 4:54 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try use this UDF, where the parameters sInput contains values like 1234567890 and sNoOfChars has number of retunr characters.
Argument:
sInput
sNoOfChars
=============
int iStartIndex = 0;
int iNoOfChars = Integer.parseInt(sNoOfChars);
iStartIndex = sInput.length() - iNoOfChars;
iStartIndex = ((iStartIndex < 0) ? 0 : iStartIndex);
return sInput.substring(iStartIndex);
Regards
Ramg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.