DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
No More String Errors - String(3C++)

String functions

There are String-oriented replacements for some of the functions described in section 3 manual pages.


strcmp
int strcmp(const String&,const String&);

strcmp(s, t) returns <0, 0, or >0 depending on whether String s is lexicographically less than, equal to, or greater than String t. It is an overloaded function so that you can use strcmp on character pointers as well.


strchr, etc.
int String::strchr(char) const;

The operators strchr, strrchr, strpbrk, strspn, and strcspn are related to the corresponding operations from string(3), but they return integer offsets instead of character pointers. Hence they must be member functions and not overloaded ordinary functions. Thus s.strchr(c) (s.strrchr(c)) returns the index of the first (last) occurrence of the character c in the String s. (Remember the offset of the first character of a String is 0.) If c does not occur in the String, - 1 is returned. s.strpbrk(t) returns the index of the first occurrence in String s of any character from String t, or -1 if no character from t exists in s. s.strspn(t) (s.strcspn(t)) returns the length of the initial segment of String s that consists entirely of characters from (not from) String t.

UNIX System and Library Calls

There are String versions of some of the functions in sections 2 and 3 of the manual pages ( read(2), write(2), gets(3S), fgets(3S), puts(3S), fputs(3S)) that have const character pointer arguments. All functions which expect a const char* will work with Strings as arguments because conversion to const char* will happen automatically. But these functions have been overloaded because they are much more efficient when implemented directly for Strings. The current manual descriptions apply except that const char* is replaced by String. Standard functions that return char* can be used to return a String since conversion of the result from char* to String will happen automatically as well.


Next topic: Implementation
Previous topic: Comparison Operations

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004