79334555

Date: 2025-01-06 23:14:38
Score: 0.5
Natty:
Report link

Solution using Regular Expressions:

#include <iostream>
#include <regex>

std::string line = "{10}{20}Hello World!";

// Regular expression, that contains 3 match groups: int, int, and anything
std::regex matcher("\\{(\\d+)\\}\\{(\\d+)\\}(.+)");

std::smatch match;
if (!std::regex_search(line, match, matcher)) {
  throw std::runtime_error("Failed to match expected format.");
}

int start = std::stoi(match[1]);
int end = std::stoi(match[2]);
std::string text = match[3];
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: dczajkowski