| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

searchreplace

#include "sflstr.h"
char *
searchreplace (
    char *strbuf,
    char *strtofnd,
    char *strtoins)

Synopsis

A case insensitive search and replace. Searches for all occurances of a string, and replaces it with another string. Returns a pointer to head of the buffer. Submitted by Scott Beasley jscottb@infoave.com

Source Code - (sflstr.c)

{
   char *offset, *strbase;

   ASSERT (strbuf);
   ASSERT (strtofnd);
   ASSERT (strtoins);

   offset = strbase = (char *)NULL;

   while (*strbuf)
     {
       offset = stricstr (!offset ? strbuf : strbase, strtofnd);
       if (offset)
         {
           strbase = (offset + strlen (strtoins));
           strcpy (offset, (offset + strlen (strtofnd)));
           memmove (offset + strlen (strtoins),
                     offset, strlen (offset) + 1);
           memcpy (offset, strtoins, strlen (strtoins));
         }

      else
           break;
     }

   return strbuf;
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation