In Part 1 I looked at why I am using Derby and in Part 2 I looked at how to create custom functions. In the final part of this series we are going to look at the actual code to create our functions.

So in the last part we took a look at writing a replace function. In my example I needed to use a replace function on a database field. To create that function we have a class that looks like this. Then I started thinking, what If I need to replace many instances of a string. The function above will only replace the first occurrence. No problem, as I said before we can take this opportunity to create a whole library of functions to use.

When I actually got back to writing my application I noticed another problem. What if I had to replace more than 1 item? With our current replace method I would have to do something like this. That obviously does not make much sense so what I want to do is write a function that allows to replace multiple strings. In my case I am going to write a function that allows for a regular expression. Now I could do something like this. On top of that I came up with a couple other methods that I thought I could use.

I also want to take the chance to get everyone into the mode of unit testing, so please take a chance watch this public service announcement.

As you can see its pretty easy to create your own functions. On top of being extremely easy you can see its pretty powerful. I just really like being able to create methods in a familiar environment. I have attached my jar file that contains my StringUtils class but you can just as easily create your own. I hope to add some more classes + methods in the future so please give me your suggestions.