| iMatix home page | << | < | > | >> |
SFL Version 2.11 |
#include "sflstr.h" char * stringreplace ( char *strbuf, char *strpattern)
This function searches for known strings, and replaces them with another string.
stringreplace (strfilename, "sqv|sqr,ruv|run,h_v|h"); This example would replace all occurences of sqv, with sqr, ruv with run and h_v with h. Returns pointer to head of the return buffer. Submitted by Scott Beasley <jscottb@infoave.com>
{ int ilen, ifld = 0; char *strsrch, *strrpl, *strpat; ASSERT (strbuf); ASSERT (strpattern); if (!strpattern) return strbuf; while (1) { ilen = getstrfldlen (strpattern, ifld, 0, ","); if (!ilen) break; strpat = (char *)malloc (ilen + 1); getstrfld (strpattern, ifld, 0, ",", strpat); ifld++; ilen = getstrfldlen (strpat, 0, 0, "|"); strsrch = (char *)malloc (ilen + 1); getstrfld (strpat, 0, 0, "|", strsrch); ilen = getstrfldlen (strpat, 1, 0, "|"); strrpl = (char *)malloc (ilen + 1); getstrfld (strpat, 1, 0, "|", strrpl); searchreplace (strbuf, strsrch, strrpl); free (strsrch); free (strrpl); free (strpat); } return strbuf; }
| << | < | > | >> | Copyright © 1996-2000 iMatix Corporation |