I’m glad Martin found a solution to his liking. I doubt it is the most efficient, but it is straight forward coding, easy to understand, and gets the job done.
I think what this type of problem cries out for is an EXAMINE FOR LEADING, or EXAMINE FOR … DELETE/REPLACE LEADING, like the COBOL EXAMINE statement has always had. I’ve always missed having the “LEADING” option, which could also function as a “TRAILING” option when combined with EXAMINE BACKWARD. The NATURAL developers added the “FIRST” option a while back, but it’s not quite the same. As Helmut’s excellent example illustrates, use of DELETE FIRST for this problem requires use of an extra MASK (*‘"/) test to determine if the '’ is actually a trailing character before using an EXAMINE to delete it. (Cool - I had forgotten the / in the MASK checks for a trailing pattern.) Also, a loop is required to delete or replace multiple '_'s. An EXAMINE with a “LEADING” option could do it all with just one statement. (Hint, hint, Wolfgang
I’ve been trying to test the efficiency of the first 2 versions, Jerome’s & Ralph’s, and my version similar to Helmut’s on my home PC with NaturalONE CE. Using the original (A30) “HELLOWORL_D__” test string, 10,000 iterations, my & Helmut’s version came in first, CPU=.03 sec, Ralph’s 2nd, .06 sec, and Jerome’s (& Steve’s?) 3rd at .17 sec. I need to change Ralph’s version to the smaller #GOOD array, since the NatONE Profiler showed most of the CPU time spent on the EXAMINE statement running through the #GOOD(A256) array. I expected Ralph’s to be fastest of all, but I’m not sure why his test results for Helmet’s version are so slow. More testing to come, just for grins, bump my loop count up to 100,000 for better resolution, and maybe follow Ralph’s logic to subtract out the FOR loop CPU time.
I can understand Steve’s objection to the 2nd subscript added to the character array method, probably causing extra CPU costs. Maybe Ralph’s code could be changed to rename the #TEXT (A50/5) to #TEXT-ARY (A50/5), add a 1 dimension #TEXT (A50), redefined by #T(A1/50) . Instead of RESET INITIAL #TEXT (*) at the top of each loop, just move the next occurrence, #TEXT-ARY (#J) to #TEXT.
Hope Steve’s move goes well, and he can recuperate somewhat before getting back to this. I’m curious why he prefers indexing through a redefined character array for this situation. I thought he almost always in the past had showed the EXAMINE working on a string to be the most efficient, CPU-wise.
Cheers to all,
George