frankcollins3 / fcc-mcsft-cSharp

FreeCodeCamp & Microsoft C# course:
1 stars 0 forks source link

fun/interesting issue. scope and declaration [6:06pm] #32

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago

attempting to do: remove the closing </div> tag from the string Screen Shot 2023-09-10 at 6 03 51 PM

error: range/out-of-bounds limit Screen Shot 2023-09-10 at 6 04 00 PM

proposed approach: if correct, neat issue where the problem is. the initial finding of the index is done before any .remove() finding the closing tag should be done after the first .Remove() statement eliminates the opening <div>

// last assumption on a separate index related problem was wrong so this could be wrong too.

possible improvements:

frankcollins3 commented 1 year ago

also the establishing of </div> should be performed on {quantity}: the newly declared string to which .Remove() && .Replace() have already applied. [6:07pm]

frankcollins3 commented 1 year ago

for this code:

        void stringMutation()
        {
        int openingDivLessThan = input.IndexOf("<");
        int openingDivGreaterThan = input.IndexOf(">");            

        openingDivGreaterThan += 1;
        // doesn't need the +1 as it is the last character in the string.

        quantity = input.Remove(openingDivLessThan, openingDivGreaterThan);

        int closingDivLessThan = quantity.LastIndexOf("<");
        int closingDivGreaterThan = quantity.LastIndexOf(">");

        quantity = input.Remove(closingDivLessThan, closingDivGreaterThan);
        // quantity = input.Remove(closingDivLessThan, closingDivGreaterThan);
        quantity = quantity.Replace("&trade", "&reg");
        }

➜ TestProject git:(master) ✗ dotnet run Unhandled exception. System.ArgumentOutOfRangeException: Index and count must refer to a location within the string. (Parameter 'count') at System.String.Remove(Int32 startIndex, Int32 count) [6:09pm]

tangled up. going to run logs and do a hardcoding .Remove() of </div> instead of working expression. [6:12pm]

frankcollins3 commented 1 year ago

code: Screen Shot 2023-09-10 at 6 23 39 PM output: Screen Shot 2023-09-10 at 6 22 00 PM [6:24pm]