C++ Extract Substring Code Example


Example 1: std::substring

// string::substr #include <iostream> #include <string>  int main () {   std::string str="We think in generalities, but we live in details.";                                            // (quoting Alfred N. Whitehead)    std::string str2 = str.substr (3,5);     // "think"    std::size_t pos = str.find("live");      // position of "live" in str    std::string str3 = str.substr (pos);     // get from "live" to the end    std::cout << str2 << ' ' << str3 << '\n';    return 0; }

Example 2: string substr c++

s.substr(pos,len);

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable