BOOTSTRAP (kutils) functions


LIBRARY ROUTINE

kstring_replace - replace one substring with another

LIBRARY CALL

char *kstring_replace(
   const char *istr,
   const char *scan_str,
   const char *replace_str,
   char *ostr)

INPUT

OUTPUT

RETURN VALUE

The converted string, 'ostr', if the variable is not NULL, or a pointer to the resulting allocated string. NULL is returned if 'istr' or 'scan_str' are NULL, or if an error occurs.

DESCRIPTION

This function performs a global change of text on the input string. It returns a string where every occurrence of the scan string is replaced with the replacement string. If 'ostr' is sent in as NULL, the result will be allocated for you. If 'ostr' is provided as non-NULL, the result will be stored in it. Note that if the latter use is chosen, ostr must be previously allocated with a sufficient amount of storage space before this routine is called.

Note that if 'ostr' is non-NULL, the calling routine must ensure that 'ostr' points to a memory buffer large enough to hold the copied string and terminating null character. If the buffer is not large enough, memory will be overwritten resulting in unpredicable program failure.

ADDITIONAL INFORMATION

none

EXAMPLES

For example, if we call:
new_string = kstring_replace("Welcome to Khoros", "Khoros",
"the Twilight Zone", NULL);
the result will be:
new_string = "Welcome to the Twilight Zone".

SIDE EFFECTS

This routine allocates the space for the output if 'ostr' is NULL.

RESTRICTIONS

none

MODIFICATION

none

FILES

$BOOTSTRAP/objects/library/kutils/src/strings.c

SEE ALSO

kutils(3)

COPYRIGHT

Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.