home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * st_sub.c - string substring functions.
- *
- * Purpose: This file contains string substring functions for
- * extracting parts of a given string.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <string.h>
- #include "blackstr.h"
-
-
- /********
- *
- * st_subc(string,c,subc) - substitute a character in a string
- *
- **/
-
- char *st_subc(
- char *string, /* string to sub in */
- char c, /* character to sub for */
- char subc) /* char to sub */
- {
- char *ptr;
- ptr = string;
- while(*string) {
- if(*string==c)
- *string = subc;
- ++string;
- }
- return(ptr);
- }
-
-
- /********
- *
- * st_left(str1,str2,n) - extract left n characters of str2 to str1
- *
- **/
-
- char *st_left(
- char *str1, /* string extracted */
- char *str2, /* string to extract from */
- short int n) /* # characters to extract */
- {
- return(strncpy (str1,str2,n));
- }
-
-
- /********
- *
- * st_right(str1,str2,n) - extract right n characters of str2 to str1
- *
- **/
-
- char *st_right(
- char *str1, /* string extracted */
- char *str2, /* string to extract from */
- short int n) /* # characters to extract */
- {
- while(*str2)
- ++str2; /* go to end of string 2 */
- while(n--)
- --str2; /* and back up n */
- return(strcpy (str1,str2));
- }
-
-
- /********
- *
- * st_substr(str1,str2,pos,n) - extract str1 from str2 at pos for n
- *
- **/
-
- char *st_substr(
- char *str1, /* string extracted */
- char *str2, /* string to extract from */
- short int pos, /* starting position (from left) in str2 */
- short int n) /* # bytes to extract */
- {
- while(pos--)
- ++str2; /* go to starting position in str2 */
- return(strncpy(str1,str2,n)); /* copy n bytes */
- }
-
-