## std::string cheatsheet

(c-string is fairly popular and more widespread)

An experienced java developer usually memorizes 10 methods of String.java. ditto for std::string. (See the STL book or the Absolute c++ book.)

  • insert() has many overloads
  • push_back() a single char
  • append() and operator+=() can even take in a single char, or a repetition of a char
  • operator+() to concat
  • substr() returns a COPY
  • find(a char or cStr or std::string)
  • find_first_of(a collection of candidate chars, passed in as a string),
    • find_first_of(char) is same as find(char), according to my test
  • find_last_not_of() //trim
  • at() can read-WRITE a single element.
    • operator[] is faster, but without range check, as with std::vector!
  • front() back() can read-WRITE the character
  • transform(word.begin(), word.end(), word.begin(), ::tolower)
  • std::string trailing space trim
  • c++split string on custom delimiter char
  • begin(), rbegin(), end(), rend()
  • replace() has many overloads
  • to_string(int_or_float) // c++11
  • clear()
  • empty()
  • myStr.capacity() // like vector

…. see http://www.cplusplus.com/reference/string/string/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s