mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
41 lines
1.9 KiB
HTML
41 lines
1.9 KiB
HTML
<p><strong>HTML entity parser</strong> is the parser that takes HTML code as input and replace all the entities of the special characters by the characters itself.</p>
|
|
|
|
<p>The special characters and their entities for HTML are:</p>
|
|
|
|
<ul>
|
|
<li><strong>Quotation Mark:</strong> the entity is <code>&quot;</code> and symbol character is <code>"</code>.</li>
|
|
<li><strong>Single Quote Mark:</strong> the entity is <code>&apos;</code> and symbol character is <code>'</code>.</li>
|
|
<li><strong>Ampersand:</strong> the entity is <code>&amp;</code> and symbol character is <code>&</code>.</li>
|
|
<li><strong>Greater Than Sign:</strong> the entity is <code>&gt;</code> and symbol character is <code>></code>.</li>
|
|
<li><strong>Less Than Sign:</strong> the entity is <code>&lt;</code> and symbol character is <code><</code>.</li>
|
|
<li><strong>Slash:</strong> the entity is <code>&frasl;</code> and symbol character is <code>/</code>.</li>
|
|
</ul>
|
|
|
|
<p>Given the input <code>text</code> string to the HTML parser, you have to implement the entity parser.</p>
|
|
|
|
<p>Return <em>the text after replacing the entities by the special characters</em>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> text = "&amp; is an HTML entity but &ambassador; is not."
|
|
<strong>Output:</strong> "& is an HTML entity but &ambassador; is not."
|
|
<strong>Explanation:</strong> The parser will replace the &amp; entity by &
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> text = "and I quote: &quot;...&quot;"
|
|
<strong>Output:</strong> "and I quote: \"...\""
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= text.length <= 10<sup>5</sup></code></li>
|
|
<li>The string may contain any possible characters out of all the 256 ASCII characters.</li>
|
|
</ul>
|