I started learning C ++ and my task is to replace some characters in the text. Something similar to the template Here are some examples:
<h1>Title</h1>$ js $<p>text...</p>
result:
<h1>Title</h1> </script>alert(1)</script> <p>text...</p>
I tried to do it with this code, but nothing worked:
#include <iostream>
#include <string>
using namespace std;
int main(){
string text = "<h1>Title</h1>$ js $<p>text...</p>";
string js_code = " </script>alert(1)</script> ";
string result = text.replace(text.find("$ js $"), js_code.length(), js_code);
cout << result << endl;
return 0;
}
result:
<h1>Title</h1> </script>alert(1)</script>
The text was inserted into the line, but everything after this text disappeared. Also, sometimes I will use Russian characters, and they are in UTF-8 encoding. 1 Symbol weighs more.