on 02-21-2011 10:58 PM
I am using a substring function to get the 1st eight char of the string but the mapping fails if the input has no data, how can I handle this?do we have to write a UDF for this?please help
Thanks
Hi,
You can use this simple UDF which takes a single String array as input , say s[ ] and it has a single ResultList item named result as output.
The complete code is as follows:
public void substrn(String[] s,ResultList result,Container c)
{
if((s[0]!=null) && (s[0].length()>0))
{
result.addValue(s[0].substring(0,8);
}
else
result.addValue("");
}
Map the output of this UDF to the target side field.
Thanks
Biswajit
Edited by: 007biswa on Feb 22, 2011 8:45 AM
Edited by: 007biswa on Feb 22, 2011 8:46 AM
Edited by: 007biswa on Feb 22, 2011 8:48 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
No need to use UDF. You can try using the mapping below:
source --> mapWithDefault: --> substring(0,8) --> trim --> target
The source context should be unmodifiend. The value of mapWithDefault contains 8 spaces. The trim will be used to eliminate whitespaces.
Hope this helps,
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use the standard length function to check if the string length is greater than 8 as well instead of checking for just 0.
Because if your input string is less than 8 then also substring will throw an error.
Regards,
Vishal
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 first check if the field exist using standard node function "exists" and then compare it with empty constant.
If it exists and is not empty then you can use substring function to send 8 characters to target. if its empty you can simply send empty constant to target. No need for UDF here.
Regards,
Deepak
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
There is no need of UDF for this.
You can handle this with a simple logic using equalS text function and "if then else" boolean function.
SourceString -> constant " "(8 spaces) to then
equalS -> <if then else> --->substring(0...8) -- > Target Field
constant ""(blank) -> SourceString to else
I think this should satisfy your requirement.
Regards,
Aravind
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>>> if the input has no data, how can I handle this?do we have to write a UDF for this?please help
Solution 1)
Use standard length function and see the value of the string... if the string has length > 0, then do the substring to pull first 8 characters.
you dont need UDF for this simple logic... if you want, you can use the below UDF too...
solution 2)
Example your input string variable in the udf method is inputString, do as follows
String output="";
if (inputString!=null && inputString.length() >0){
output = inputString.substring(0,8);
}
return output;
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.