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().
Haven't tried it yet, but you make an interesting point, so I'm going to try that now.
We already are using Roland's n_stringClass in some places.
I'll let you know about the results, or even better, I'll build it in in the sample I'm making for Olaf.
regards
the Replace of .Net absolutely rules when it comes to replacing all occurrences. If it's just a single replace of a single occurrence, we can just use the PB function, seems to be even slightly faster in some cases.