I was doing this one exercise on Microsoft’s website where you were supposed to extract, replace, and remove data from an input string and get a this output:
Quantity: 5000
Output:
Widgets ®
5000
And now I wonder did I wrote a shitty or somewhat decent code?
const string input = "<div><h2>Widgets ™</h2><span>5000</span></div>";
string quantity= "";
string output = "";
const string openSpan = "<span>";
const string closeSpan = "</span>";
int openingP= input.LastIndexOf(openSpan);
int closingP= input.LastIndexOf(closeSpan);
openingP += openSpan.Length;
int length= closingP- openingP;
quantity=input.Substring(openingP, length);
string Updatedinput = input.Replace("™","®");
Updatedinput = input.Replace("</div>","");
string newUpdatedInput= Updatedinput.Remove(1,5);
Console.WriteLine(newUpdatedInput);
Console.WriteLine($"quantity-{quantity}");
Console.WriteLine(output);
New contributor
yehor shchehlov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.