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

Miscellaneous


match
int String::match(const String&) const;

s.match(t) returns the length of the initial common substring of s and t; returns the length if the Strings do not differ. The String argument can also be a character pointer.

String::firstdiff(const String&) const;

s.firstdiff(t) returns the first position at which s differs from t; returns -1 if the Strings do not differ or if s is an initial substring of t. The String argument can also be a character pointer.


index
int

String::index(const String&,int pos=0) const;

int

String::index(char,int pos=0) const;

If t is a substring of s, s.index(t,pos) returns the first position (which is >= pos) at which they coincide; it returns -1 otherwise. If c is an element of s, s.index(c,pos) returns the first position (which is >= pos) at which c appears in s; it returns -1 otherwise.


upper
String String::upper() const;

s.upper() returns a new String constructed from s as follows: for each character c of s, if c is lowercase, the result is the uppercase version of c; otherwise the result is c.


lower
String String::lower() const;

s.lower() returns a new String constructed from s as follows: for each character c of s, if c is uppercase, the result is the lowercase version of c; otherwise the result is c.


dump
char* String::dump(char *) const;

s.dump(p) fills the buffer pointed to by character pointer p with the characters of String s, followed by a null character, and returns the character pointer. It is up to the programmer to be sure the buffer is large enough. This function is an ``escape hatch'' to old-style C strings.


hashval
int String::hashval() const;

s.hashval() returns a non-negative integer derived from String s to be used in hash tables, etc. The algorithm involves a sequence of xors and shifts. (But see also Symbol(C++) for more on using strings as keys.)


Next topic: Programming Examples
Previous topic: Unsafe Programming with Strings

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