fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. std::string getValue(const std::string &html)
  5. {
  6. static const std::string VALUE = "value";
  7. static const char DOUBLE_QUOTE = '"';
  8.  
  9. std::string result;
  10.  
  11. std::size_t pos = html.find(VALUE);
  12. if (pos != std::string::npos)
  13. {
  14. std::size_t beg = html.find_first_of(DOUBLE_QUOTE, pos);
  15.  
  16. if (beg != std::string::npos)
  17. {
  18. std::size_t end = html.find_first_of(DOUBLE_QUOTE, beg + 1);
  19.  
  20. if (end != std::string::npos)
  21. {
  22. result = html.substr(beg + 1, end - beg - 1);
  23. }
  24. }
  25. }
  26.  
  27. return result;
  28. }
  29.  
  30. int main()
  31. {
  32. std::string html = "<input type=\"hidden\" name=\"wtkn\" value=\"56e45dbe_wNIT/DcufUPvZOL33jmkyqGpKxw=\">";
  33. std::cout << "HTML: " << html << "\n";
  34. std::cout << "value: " << getValue(html) << "\n";
  35. return 0;
  36. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
HTML: <input type="hidden" name="wtkn" value="56e45dbe_wNIT/DcufUPvZOL33jmkyqGpKxw=">
value: 56e45dbe_wNIT/DcufUPvZOL33jmkyqGpKxw=