CPP/Strings/SingleCharacterTag

From ProgrammingExamples
< CPP
Revision as of 18:14, 28 June 2010 by Daviddoria (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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))
    }
  }
 
  return 0;
}