I want to manipulate the following HTML structure using C#, and move the bgcolor attribute inside the style attribute as shown below, I want to achieve it using string manipulation (Or any other suitable method if applicable) is there a way possible:
Present Structure
<body>
<div bgcolor="#342516" style="color: red; font-size:10px;">ABCD</div>
<div bgcolor="#342516" style="color: red; font-size:10px;">EFGH</div>
<div bgcolor="#342516" style="color: red; font-size:10px;">HIJK</div>
<div bgcolor="#342516" style="color: red; font-size:10px;">LMNO</div>
</body>
Required Output
<body>
<div style="background-color:#342516; color: red; font-size:10px;">ABCD</div>
<div style="background-color:#342516; color: red; font-size:10px;">EFGH</div>
<div style="background-color:#342516; color: red; font-size:10px;">HIJK</div>
<div style="background-color:#342516; color: red; font-size:10px;">LMNO</div>
</body>
2
Answers
I don’t think you need to program to solve this, a text editor will suffice. As far as I know, both VS Code and NotePad++ support replacing text by folder.
If You really need it in C# the most simple solution is string.replace(). for any other more complex text You need regular expression