# String Utilities

Topics

:

Overview
Conditional Directives
Constants
Functions

Overview

The string utilities are a collection of data structures and standalone functions used to manipulate and parse null terminated character strings.

Conditional Directives

The following conditional directives are used to define non-portable string routines that need to be ported between UNIX and WIN32 platforms.

__DOS__

- Directive used for all DOS compilers

__UNIX__

- Directive used for all UNIX compilers

__WIN32__

- Directive used for all WIN32 compilers

Constants

    const int MAXWORDLENGTH = 255; // Maximum word length
    const int MAXWORDS = 255;      // Maximum number of words

Functions

String concatenation routines

:
char *StringCat(const char *s1=" ", const char *s2= " ", const char *s3=" ") - Standalone function used to append up to three strings onto the end of each other. Returns a null-terminated string representing "s2" and "s3" concatenated onto the end of "s1." The calling function is responsible for freeing the memory allocated for the composite string returned by this functions.

String parser

:
int parse(char *string, char words[MAXWORDS][MAXWORDLENGTH], int *numwords, char sepchar) - The global integer constants MAXWORDS and MAXWORDLENGTH define the maximum number of words and the maximum word length that will be parsed. Both are equal to 255. The number of words parsed is passed back in the "numwords" variable and the actual words parsed from the line of text are passed back in the "words" array.

Case insensitive string compare functions

:
int CaseICmp(const char *s1, const char *s2) - Standalone function used to perform a case insensitive string compare. Returns -1 if "s1" is less then "s2", 0 if "s1" equals "s2" and 1 if "s1" is greater then "s2."

String searching functions

:
unsigned FindMatch(const char *str, const char *p, unsigned offset = 0) - Finds pattern "p" in string "s" starting a specified offset. Returns index of first occurrence of matching the pattern or -1 if no match is found.

unsigned IFindMatch(const char *str, const char *p, unsigned offset = 0)

- Finds pattern "p" in string "s" starting a specified offset using a case insensitive compare. Returns index of first occurrence of matching the pattern or -1 if no match is found.

End Of Document