( Search & copy ) in a new file text from string ??

Hello Everyone
I know I can do this with c++ but I don't Know How !!!
anyway I will tell you maybe can someone help me :)

I have a file text date type string and I want search in this file for a sentence ( /santa-diabla/video/santa-diabla-ep-@/@@@@@@@@ )

Note: ( @/@@@@@@@@ ) is a variable

and after search I want copy all sentence in a new file text, there is 136 sentence .

( look at this photo for understand more what I want )

https://i.postimg.cc/Jz0SvwF2/Untitled.png


of course I can do this manually ... but what benefits c++ if I do it manually hhhh =D

if anyone want know why I want do this ... because I want download subtitles for Tv series " Santa Diabla " from site " https://www.nbc.com/ "
Last edited on
Use a regular expression: href\=\"(\/santa\-diabla\/video\/santa\-diabla\-ep\-\d+/\d+)\"
Search the file for that pattern and get group 1 from each match.
@helios

can you do it for me please ❤️

this is the file on one drive :

https://1drv.ms/t/s!AqPOyLnFsNTObVX-eGh8FwmWWxY?e=7Bl9
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <fstream>
#include <string>
#include <iterator>
#include <iostream>

int main()
{
	const std::string tofind {R"(/santa-diabla/video/santa-diabla-ep)"};

	std::ifstream ifs("hj.txt");
	std::ofstream ofs("newhj.txt");

	if (!ifs || !ofs)
		return std::cout << "Cannot open files!\n", 1;

	const std::string data((std::istream_iterator<char>(ifs)), std::istream_iterator<char>());

	if (data.empty())
		return std::cout << "Error reading data\n", 2;

	int cnt = 0;

	for (size_t fnd = 0, fndq = 0; (fnd = data.find(tofind, fnd)) != std::string::npos; fnd = fndq) {
		fndq = data.find('"', fnd);
		ofs << data.substr(fnd, fndq - fnd) << '\n';
		++cnt;
	}

	std::cout << cnt << " instances found\n";
}


which displays that the required 136 file names have been found and extracted to the specified output file from the specified input file.
Last edited on
@seeplus

How I can run this function brother ??

https://i.postimg.cc/2y4xXfYs/Untitled.png
I only use MS VS - I don't know code::blocks. This compiles and runs OK with VS 2019.

Look at the first warning message - you need to use the specified compiler options.

Last edited on
@seeplus

Brother I can't download 7 GB for one function :'(

https://i.postimg.cc/W4g7LWS0/Untitled.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

if( " visual studio 2010 " = enough ){

 cout << " Maybe I will download it from here : https://ar4up.com/visual-studio-2010-full-version/ " << endl;

just Maybe hhh it is 2 GB brother;


}if else ( "can you do it for me please ❤️ " = Yes ){

 cout << " Thank you So Much " << " + " << " you can download file 'hj' from here:  " << " https://1drv.ms/t/s!AqPOyLnFsNTObVX-eGh8FwmWWxY?e=7Bl9 " << endl;

}else ( " visual studio 2010 " != enough && "can you do it for me please ❤️ " != Yes ){

cout << " Thank You Very Very much Brother For All Thing did it for me " << endl;

} 


Last edited on
You're compiling as c++98 with code::blocks. That version of C++ is ancient. To compile using the current standard requires some command line options to be used. The warning message suggests what to use. If you're going to be doing much C++ programming, you need to know how to compile using the current standard. As I said, I only use MS VS so can't really say how to with code::blocks

However, I've tried to 'strip out' the non-C++98 stuff from above. Try:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <fstream>
#include <string>
#include <iterator>
#include <iostream>

int main()
{
	const std::string tofind = "/santa-diabla/video/santa-diabla-ep";

	std::ifstream ifs("hj.txt");
	std::ofstream ofs("newhj.txt");

	if (!ifs || !ofs)
		return std::cout << "Cannot open files!\n", 1;

	const std::string data((std::istream_iterator<char>(ifs)), std::istream_iterator<char>());

	if (data.empty())
		return std::cout << "Error reading data\n", 2;

	int cnt = 0;

	for (size_t fnd = 0, fndq = 0; (fnd = data.find(tofind, fnd)) != std::string::npos; fnd = fndq) {
		fndq = data.find('"', fnd);
		ofs << data.substr(fnd, fndq - fnd) << '\n';
		++cnt;
	}

	std::cout << cnt << " instances found\n";
}


@seeplus

Now it is very coooooooooooooooooooooooooooooooooooool Thank you very very much brother ❤️ ❤️ ❤️

https://i.postimg.cc/Yq0vH0Mt/Untitled.png

c++ it is the Magic I love it hhh =D
Last edited on
Registered users can post here. Sign in or register to post.