cancel
Showing results for 
Search instead for 
Did you mean: 

Converting alpha numeric to 0's format

former_member210677
Participant
0 Kudos

HI Experts,

Could you please help me to convert the alphanumeric(DN20110141960003) format to 000000000000000 format.

thanks

Ranganath.

Accepted Solutions (1)

Accepted Solutions (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

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.

former_member210677
Participant
0 Kudos

Hi Baskar,

may i know if we have any standard function for this? and i want to know how can we convert the dynamic alpha numberic values to 0's

thanks for your prompt reply

Thanks

Ranganath

sahithi_moparthi
Contributor
0 Kudos

Hi Dasari,

         Using UDF is good idea.Acheiving this through Standard Function might be  difficult.

Regards,

Sahithi M

baskar_gopalakrishnan2
Active Contributor
0 Kudos

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.

former_member184681
Active Contributor
0 Kudos

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

Answers (1)

Answers (1)

rajasekhar_reddy14
Active Contributor
0 Kudos

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