PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : String Methoden



wual
14-10-2004, 09:59
Hi Leute.
Ganz schnell wie lautet die Methode aus String vo ich die erste n Zeichen nach einen String muster vergleichen kann. (C++)

ca. so ich habe einen String "TCP654654asdfwer", und ich will abfragen,
wenn die erste 3 TCP dann mache das oder das.

DAnke

wraith
14-10-2004, 10:12
basic_string::compare

int compare(const basic_string& right) const;
int compare(size_type off, size_type n0,
const basic_string& right) const;
int compare(size_type off, size_type n0,
const basic_string& right, size_type roff, size_type count) const;
int compare(const value_type *ptr) const;
int compare(size_type off, size_type n0,
const value_type *ptr) const;
int compare(size_type off, size_type n0,
const value_type *ptr, size_type off) const;

The member functions each compare up to n0 elements of the controlled sequence beginning with position off, or the entire controlled sequence if these arguments are not supplied, to the operand sequence. Each function returns:

* a negative value if the first differing element in the controlled sequence compares less than the corresponding element in the operand sequence (as determined by traits_type::compare), or if the two have a common prefix but the operand sequence is longer
* zero if the two compare equal element by element and are the same length
* a positive value otherwise

panzi
15-10-2004, 23:48
oder in c strncmp (http://unixhelp.ed.ac.uk/CGI/man-cgi?strncmp) (und strncasecmp (http://unixhelp.ed.ac.uk/CGI/man-cgi?strncasecmp)).