on 05-21-2012 11:47 AM
HI Experts,
Could you please help me to convert the alphanumeric(DN20110141960003) format to 000000000000000 format.
thanks
Ranganath.
you might write UDF or standard function to achieve this. Example as below.
return new String().replace(alpha, "000000000000000"};
Assume that your input parameter type is string and the name is alpha.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you always assume that string length is same and value is alphanumeric and convert all the chars to zeros than my above UDF will work. If you want to check dynamic alphanumeric values and convert each char as zero then you might have to use Raja's link but need to do below modification to work. Are you required to convert all digits to zero as output? If so follow this code...
Create input as string parameter name in the UDF method. and the below logic is required...
String result = new String();
for(char c : input.toLowerCase().toCharArray()) {
switch(c) {
case '0': result+="0"; break;
case '1': result+="0"; break;
case '2': case 'a': case 'b': case 'c': result+="0"; break;
case '3': case 'd': case 'e': case 'f': result+="0"; break;
case '4': case 'g': case 'h': case 'i': result+="0"; break;
case '5': case 'j': case 'k': case 'l': result+="0"; break;
case '6': case 'm': case 'n': case 'o': result+="0"; break;
case '7': case 'p': case 'q': case 'r': case 's': result+="0"; break;
case '8': case 't': case 'u': case 'v': result+="0"; break;
case '9': case 'w': case 'x': case 'y': case 'z': result+="0"; break;
}
}
return result;
Map the input field to UDF and the output of UDF to target element.
Hi,
First of all - if you really have to, you could do the conversion with standard Text function replaceString. Unfortunately this function cannot work with regular expressions, so you would have to replace every single non-numeric character manually one by one, which I believe you don't want to do.
For the UDF, a single-line function should be enough (for execution type single values):
return input.replaceAll("[^\\d]", "");
It replaces all non-digits with an empty string (so simply deletes them), but you could also replace with zero or anything else, as required (by changing the second attribute accordingly).
Regards,
Greg
Refer below link and copy the code and convert as a UDF.
http://stackoverflow.com/questions/1462834/how-to-convert-an-alphanumeric-phone-number-to-digits
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
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.