Hi,
TIP:
I don't know if anyone has a similar function, so this is just a tip.
We have a global function "f_str_replace()", which uses a loop with the powerbuilder Pos() and Replace() functions to replace all occurrences of an "old" piece of string within a string and replaces them with a "new" piece of string.
Now that - with pb2019 r2 - it's way easier to call a c# function in a DLL, I decided to replace that function with the Replace() of C#. It no longer needs a loop to find and replace all "old" strings. It's a single call to Replace() in .Net.
This makes the replace between 500 and 600 times faster on my machine. (this is very much depending on how big the strings are and what you might be replacing with what).
We use this replace function in lots of places, so it's pretty useful.
We instantiate the .Net caller object in a global variable, so it only has to be done once.
(If anyone's interested and needs source code, just let me know).
regards
MiguelL
BTW: I tried to see if .net's Substring() function is also faster than Powerbuilder's Mid() function, but that was a big disappointment. Powerbuilder's Mid() function is waaaaay faster than the .net Substring() function. Probably due to all kinds of checks with exceptions that .net does before actually performing the substring().
//Steen
For most cases your BlobMid() solution is really a lot faster than using Replace() or even Mid(). You do make an interesting point here. When I have some time I'll play around with it.
Thanks!
I did a little test and passed the as_oldstring by Reference to the ReplaceAll() function. Instead of copying it to ls_oldstring, I ommited ls_oldstring adn used the parameter itself directly.
I did a test with an initial string with a length of 616,400 characters. With my test, ByRef was only half a second faster: Current method took 134.453 seconds and byRef took 133.921 seconds. Not really worth it, since when using ByRef, you will also loose the contents of your original string (in case you want to re-use it). So if you don't want the original string to change, you'd still have to do a copy before calling ReplaceAll() and then afterwards re-assign the original value.
Regards