Post Reply 
How do you delete characters in a string?
10-31-2017, 11:59 AM (This post was last modified: 10-31-2017 12:05 PM by webmasterpdx.)
Post: #6
RE: How do you delete characters in a string?
suppress() works but it's much faster to use RIGHT() and LEFT() functions. Be careful as there are CAS functions right() and left() that are related to equations.

So, the optimal way to drop characters in a string is as follows.

Code:

// Drops characters from string
// S   string
// L   Position before first character to drop
// R   Position after last character to drop
// e.g. S:=STRDEL(S,3,7); drops S(4), S(5) and S(6) from S.
EXPORT STRDEL(S,L,R)
BEGIN
RETURN LEFT(S,L)+RIGHT(S,DIM(S)-R+1);
END; // BEGIN...

I tested this a couple of different ways using TEVAL. I ran code using a string with suppress, scanning the string using FOR loops and finally using RIGHT and LEFT. I just ran the same code 10000 times to get the timing. Note that suppress was as faster than the FOR loops for dropping a single character since it's doing much the same thing except the FOR loop in suppress is in machine code. However, when you drop multiple characters calling suppress multiple times, you are effectively scanning the string over and over again, so the FOR loop catches up when you get to 5 or so characters to drop. The RIGHT and LEFT versions was always faster for everything. Dropping 5 characters using suppress was around 70 seconds while RIGHT and LEFT was only 5 seconds....considerably faster. Dropping one character, suppress was around 15 seconds while RIGHT and LEFT was around 5 seconds still.
Enjoy.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: How do you delete characters in a string? - webmasterpdx - 10-31-2017 11:59 AM



User(s) browsing this thread: 2 Guest(s)