[Update]
We can help you fix your code, but you need to show us a finished (complete) piece of code.
If you ask 5 programmers to write a code for this problem, you will end up with 6 programs. This mean that there is not a single solution, there is many of them, some are recursive, some just loop, some RegEx ...
That is the reason you need to show your code. Without finished code, I can only give some general advices.
-----
Quote:
The code here is unfinished because I had second thoughts about my logic.
Don't stop because of this. There is only one way to know if your idea works or not: give it a try.
As a learner, you also learn what works and what don't by practicing, so you can benefit from a wrong idea.
Advice: if the problem look too complicated for you, try to solve a simplified problem.
In first try to solve the problem without nesting, once you are familiar with the simplified problem, adding the nesting is not very complicated.
Your problem is a varying of RLE compression:
Run-length encoding - Wikipedia[
^]
-----
Learn one or more analyze methods,
E.W. Djikstra top-Down method is a good start, it will help you to organize your ideas.
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[
^]
https://en.wikipedia.org/wiki/Structured_programming[
^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[
^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[
^]
-----
When your code do not behave the way you expect, and you don't understand why !
There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
The downside of this solution:
- It is a DIY, you are the one tracking the problem and finding its roots, which lead to the solution.
The upside of this solution:
- It is also a great learning tool because it show you reality and you can see which expectation match reality.
secondary effects
- Your will be proud of finding bugs yourself.
- Your learning skills will improve.
You should find pretty quickly what is wrong.
Debugger - Wikipedia, the free encyclopedia[
^]
Debugging C# Code in Visual Studio - YouTube[
^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
If you want help on your code, show it finished and state the problem you encounter.