Difference between revisions of "CPP/Strings/SingleCharacterTag"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with '==SingleCharacterTag.cpp== <source lang="cpp"> #include <iostream> #include <string> int main() { size_t firstPos = 0, secondPos; std::string temp = "some text a <tag> and m…') |
Daviddoria (Talk | contribs) |
||
Line 9: | Line 9: | ||
std::string temp = "some text a <tag> and more text"; | std::string temp = "some text a <tag> and more text"; | ||
std::string sub; | std::string sub; | ||
− | if ((firstPos = temp.find_first_of("<", firstPos)) != std::string | + | if ((firstPos = temp.find_first_of("<", firstPos)) != std::string::npos) |
{ | { | ||
− | if ((secondPos = temp.find_first_of(">", firstPos + 1)) != std::string | + | if ((secondPos = temp.find_first_of(">", firstPos + 1)) != std::string::npos) |
{ | { | ||
− | sub = temp.substr(firstPos, (secondPos - firstPos + 1)) | + | sub = temp.substr(firstPos, (secondPos - firstPos + 1)); |
} | } | ||
} | } | ||
− | + | ||
+ | std::cout << sub << std::endl; | ||
+ | |||
return 0; | return 0; | ||
} | } | ||
+ | |||
</source> | </source> |
Latest revision as of 18:45, 28 June 2010
SingleCharacterTag.cpp
#include <iostream> #include <string> int main() { size_t firstPos = 0, secondPos; std::string temp = "some text a <tag> and more text"; std::string sub; if ((firstPos = temp.find_first_of("<", firstPos)) != std::string::npos) { if ((secondPos = temp.find_first_of(">", firstPos + 1)) != std::string::npos) { sub = temp.substr(firstPos, (secondPos - firstPos + 1)); } } std::cout << sub << std::endl; return 0; }