(REPLACE FUNCTION)
Posted in 1995
> From: Robert Minter <rob@dssmktg.com> R> I found some problems with the Replace function that was posted earlier. R> If Source_String is null, the line: R> IF source_string[i, (i+old_len-1)] = old_pattern THEN etc.. R> BLOWS UP. Source_String is not checked anywhere. R> I haven't checked it completely yet. Just FYI. I have tested this code under both P-code and C compiled. Here are the results I have found: Under both versions, results are the same. If source_string is null then the replaced string is also null. It does no blow up. If the old pattern is null, then no replacement is made. If the new pattern is null, then the old_pattern is removed from the source_string. Here's the code I used for the test: (I've retyped it here, so please allow for an accidental type-o) define source_string, old_pattern, new_pattern char (80), returned_string char (200) ... prompt "Source String: " for source_string display "Source String: ", source_string at 8,1 prompt "Old Pattern: " for old_pattern display "Old Pattern: ", old_pattern at 11,1 prompt "New Pattern: " for new_pattern display "New Pattern: ", new_pattern at 14,1 let returned_string = replace(source_string, old_pattern, new_pattern) display "Returned String: " returned_string at 17,1 ... The above code was actually part of a menu option. I tried several different tests with no problems whatsoever. Tim --- ~ SPEED 1.40 [NR] ~