- Subject: Re: Re: Re: SLang tab completion - update 2002-08-05
- From: "John E. Davis" <davis>
- Date: Thu, 8 Aug 2002 18:38:19 -0400
Paul <p.boekholt@xxxxxxxxx> wrote:
>I'm using S-lang 1.4.0 and I don't have a strreplace(). I do have a
>str_replace() and a str_replace_all(). What does strreplace do and how do I
>implement it in S-lang?
Currently str_replace_all is a wrapper around strreplace, if it is
defined; otherwise it will fall back on str_replace. See site.sl for
its definition.
If str_replace uses str_replace_all as it does in your case, then can
fail to do the right thing in some situations. For example, consider
the replacement of "/" in "/a/b/c" with "/x" to produce "/xa/xb/xc".
You should find that str_replace_all using str_replace will loop
continuously with an eventual memory allocation error producing
"/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.....xa/b/c". The strreplace
function was created to fix this problem.
Since I just arrived from my vacation, I do not have time now to think
about a slang implementation of strreplace for your. However, here is
a description of the strreplace function for you or some other person
if you want to take shot at an implementation. Good luck, --John
strreplace
SYNOPSIS
Replace one or more substrings
USAGE
(new, n) = strreplace (a, b, c, max_n)
String_Type a, b, c, rep;
Int_Type n, max_n;
DESCRIPTION
The `strreplace' function may be used to replace one or more
occurances of `b' in `a' with `c'. If the integer
`max_n' is positive, then the first `max_n' occurances of
`b' in `a' will be replaced. Otherwise, if `max_n' is
negative, then the last `abs(max_n)' occurances will be replaced.
The function returns the resulting string and an integer indicating
how many replacements were made.
EXAMPLE
The following function illustrates how `strreplace' may be used
to remove all occurances of a specified substring
define delete_substrings (a, b)
{
(a, ) = strreplace (a, b, "", strlen (a));
return a;
}
SEE ALSO
is_substr, strsub, strtrim, strtrans, str_delete_chars
[Obtained from file /usr/local/doc/slang/slangfun.txt]
-----------------------------------
--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.
[2002 date index]
[2002 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]