Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If that's the only operation which operates on HTML code in your app, then you could use the solution I provided below (you can also test it online - <a href="http://ideone.com/ZgwLtE" rel="nofollow">here</a>). However, if you are going to do some more complicated parsing, then I suggest using some external library. </p> <pre><code>#include &lt;iostream&gt; #include &lt;cstdio&gt; #include &lt;cstring&gt; using namespace std; int main() { const char* beforePrefix = "asdfasdfasdfasdf"; const char* prefix = "&lt;!doctortype html"; const char* suffix = ".html&gt;"; const char* postSuffix = "asdasdasd"; unsigned size = 1024; char buf[size]; sprintf(buf, "%s%sTHE STRING YOU WANT TO GET%s%s", beforePrefix, prefix, suffix, postSuffix); cout &lt;&lt; "Before: " &lt;&lt; buf &lt;&lt; endl; const char* firstOccurenceOfPrefixPtr = strstr(buf, prefix); const char* firstOccurenceOfSuffixPtr = strstr(buf, suffix); if (firstOccurenceOfPrefixPtr &amp;&amp; firstOccurenceOfSuffixPtr) { unsigned textLen = (unsigned)(firstOccurenceOfSuffixPtr - firstOccurenceOfPrefixPtr - strlen(prefix)); char newBuf[size]; strncpy(newBuf, firstOccurenceOfPrefixPtr + strlen(prefix), textLen); newBuf[textLen] = 0; cout &lt;&lt; "After: " &lt;&lt; newBuf &lt;&lt; endl; } return 0; } </code></pre> <p><strong>EDIT</strong> I get it now :). You should use <code>strstr</code> to find the first occurence of the <code>prefix</code> then. I edited the code above, and updated the <a href="http://ideone.com/ZgwLtE" rel="nofollow">link</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload