It is better to teach a man how to fish than to teach him how to fish. I would like to share with the subject the common thinking when encountering this kind of problem.
First observe the structure of [fullText]efg[rating]. It is obvious that it consists of two tags before and after, sandwiching the content in the middle. So to extract the content in the middle of a specific tag, there must be a string matching process.
In order to make it easier to match strings, if [fullText]efg[rating] can be separated into three parts: fullText, efg, rating, and then match the first and third strings, if they match on, extract the second string.
The most basic file operation, read A.txt line by line, put the result into B.txt, separated by spaces.
Breaking it down, it has the following key functions:
Read and write files
Split string
For 2, I suggest the subject read an article I once summarized: String Segmentation Technology. For 1, it is the basic operation of C++.
The logic is very simple, just know a little bit about string operations and file operations. The code below can achieve your requirements without considering exception handling or efficiency. If necessary, you can just change it yourself
The idea is similar to @snailcoder.
It is better to teach a man how to fish than to teach him how to fish. I would like to share with the subject the common thinking when encountering this kind of problem.
First observe the structure of
[fullText]efg[rating]
. It is obvious that it consists of two tags before and after, sandwiching the content in the middle. So to extract the content in the middle of a specific tag, there must be a string matching process.In order to make it easier to match strings, if
[fullText]efg[rating]
can be separated into three parts:fullText
,efg
,rating
, and then match the first and third strings, if they match on, extract the second string.The most basic file operation, read A.txt line by line, put the result into B.txt, separated by spaces.
Breaking it down, it has the following key functions:
For 2, I suggest the subject read an article I once summarized: String Segmentation Technology. For 1, it is the basic operation of C++.
Write a simple
pickup
function:For string splitting, I directly used the function in the article mentioned above:
Finally you can call
pickup
to check whether a B.txt that meets the requirements is generated:For the complete code, please see: https://gist.github.com/pezy/7d9fb9fa74eebe819eba
Just a few lines of program using regular expressions:
If you don’t insist on using C++, it can be shorter:
The logic is very simple, just know a little bit about string operations and file operations. The code below can achieve your requirements without considering exception handling or efficiency. If necessary, you can just change it yourself