Here is what I have done. 1. I am reading the file and appending it to a string builder. 2.I am checking in a while loop is there is a beginning tag. 3.I create a substring from the beginning tag to the ending tag. 4. I check if there is another beginning tag in my substring in a while loop. 4.1 If there is not I am printing the substring. The new file content is the file content beginning from the first index of ending tag + it's length to the finish. 4.2. If there is , my substring is from the first beginning tag to the second beginning tag and I add the ending tag. The new file content is substring between last index of beginning tag and first index of ending tag plus the substring of the file from the last index of ending tag. Then I repeat. I admit that the algorithm works only if there are a maximum of 2 nested tags. Can I get some advice and some more inputs to test?