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

String functions

There are String-oriented replacements for some of the functions described in section S 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(S), 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 S and C++ of the manual pages ( read(S), write(S), gets(S), fgets(S), puts(S), fputs(S)) 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

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005