Skip to Content
Author's profile photo srinu peram

Helpful UDFs

Dear users,

Here are some UDFs that might me helpful in your business scenarios.

1. UDF to remove sequential leading values of string:


This UDF can be used in scenario where we get an input string from which we intend to pass only the required part of it, removing the leading characters which appear in a sequence. UDF consists of two input fields of which first one is input field (original string) and second one is the value which is to be deleted from the original string value.  


                                                  /wp-content/uploads/2016/08/1_1023050.png

               Code:


                        while(InputString.startsWith(Value))

                        InputString = InputString.substring(Value.length());

                        return InputString;

                 

               Examples:

              

             a.                 InputString                          Value                               Output

  

                          /wp-content/uploads/2016/08/2_1023051.png

                  b.

                           /wp-content/uploads/2016/08/3_1023074.png

                

2. UDF to Add Leading Zeroes:


This UDF can be used in a scenario where the requirement is to add leading zeroes to a string to make the total length of the string to a fixed value (for example 10).

                             /wp-content/uploads/2016/08/4_1023075.png

                    Code:

                             int defaultLength = 10;

                             String valueZero = “0”;

                             int strlength = givenString.length();

                             int diff = defaultLength – strlength;

                             String S = “”;

                             for(int i = 0; i<diff; i++)

                             S = S + valueZero;

                             return S + givenString;

                                                                 Input                                    Output

                                            /wp-content/uploads/2016/08/5_1023076.png

3. UDF to remove any number of special characters:


This UDF can be used in a business scenario where the requirement is to remove any number of special characters present in a string.

                                            Argument_List_Spclchar.png

                                  Code:

                                           givenString = givenString.replaceAll(“[^a-zA-Z0-9]+”,””);

                                           return givenString;

                                                               Input                                        Output

                                          /wp-content/uploads/2016/08/6_1023096.png

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Rajasekhar reddy
      Rajasekhar reddy

      Nice blog Srinu. If you have more UDF'S please share to us.

      Regards,

      Raja

      Author's profile photo srinu peram
      srinu peram
      Blog Post Author

      Hi Rajasekhar,

      Thank you for your feedback... 🙂

      I am working on other UDFs as well and will update them once done.

      Regards,

      Srinivas

      Author's profile photo Raghuraman S
      Raghuraman S

      Hello Rajasekhar,

      You can refer my blog for some more UDFs.. .:)

      USEFUL UDFs

      Author's profile photo Rajasekhar reddy
      Rajasekhar reddy

      Hi Raghu,

      Thanks a lot for sharing 🙂 . Very helpful blog.

      Regards,

      Raja

      Author's profile photo Evgeniy Kolmakov
      Evgeniy Kolmakov

      Hi Srinu!

      Thanks for sharing this.

      Just wanted to say, that regex expressions should be used very accurately as it can produce unwanted result.

      For example, your regex expression "[^a-zA-Z0-9]+" will remove all non-Latin symbols as well from the source string.

      Regards, Evgeniy.

      Author's profile photo srinu peram
      srinu peram
      Blog Post Author

      Hi Evgeniy,

      Thanks for your positive response 🙂

      Actually, I had a certain requirement that asked for removal of any number of special characters/symbols from the source string. Hence, I used that regex.

      Regards,

      Srinivas

      Author's profile photo Gaurav Kant
      Gaurav Kant

      Nice Blog... very helpful 🙂