Post Reply 
How do you delete characters in a string?
10-31-2017, 11:05 PM
Post: #10
RE: How do you delete characters in a string?
(10-31-2017 11:59 AM)webmasterpdx Wrote:  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...

This doesn't work if you want to drop the first or the last character of the string.
STRDEL("ABCDEFGHIJK",0,7) returns "ABCDEFGHIJKGHIJK"

Here is a working version using Cyrille substrings notation:

Code:
EXPORT STRDEL(S,L,R)
BEGIN
 LOCAL d:=DIM(S);
 IFTE(L<1,"",S(1,L))+IFTE(R>d,"",S(R,d));
END; // BEGIN...

STRDEL("ABCDEFGHIJK",0,7) returns "GHIJK"
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? - Didier Lachieze - 10-31-2017 11:05 PM



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