-
Notifications
You must be signed in to change notification settings - Fork 0
/
REPLSTR.PROC
32 lines (32 loc) · 1.4 KB
/
REPLSTR.PROC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* --------------------------------------------------------------- */
/* ReplStr: Procedure; */
/* Function to combine the DelStr and Insert functions to */
/* replace one string with another (plus other features). */
/* */
/* Author: "Dave L Clark" <[email protected]> */
/* --------------------------------------------------------------- */
Parse Arg needle,haystack,seed,opt,case;
/*
Where: needle is the string value to find,
haystack is the string value to search,
seed is the string value to replace 'needle',
opt is a Boolean value indicating whether all
occurrences of 'needle' will be replaced, and
case is a string value indicating whether to
'IGNORE' or 'MATCH' case when searching.
*/
p = 1;
If opt <> 1 Then opt = 0;
Do Until opt = 0 | p = 0 | p > Length(haystack);
If Left(case,1) == 'I' Then;
p = Pos(Translate(needle),Translate(haystack),p);
Else Do;
p = Pos(needle,haystack,p);
End;
If p > 0 Then Do;
haystack = Insert(seed,DelStr(haystack,p,Length(needle)),p-1);
p = p + Length(seed);
End;
End;
Return haystack;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */