简体   繁体   中英

How do I extract string from pattern to pattern?

I am trying to extract a string between two patterns from another string in C++.

Example of input: "C++ is not that easy"

Pattern1: "C++"

Pattern2: "that"

Result: " is not "

I would like to loop this operation to extract all matching strings from binary file later.

The best way for this is to use regular expressions.

You can read more about it here

You can use string::find() to find the position of each pattern within the input, string::length() to find the end position of the first pattern (since find() gives the start),and then string::substr() to extract the substring between those positions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM