Manipulating data in a text file

Hello, I would like to manipulate data inside a text file to do the following:

1) Read the text file and if there are any characters like this one ` skip to the next line.
2) If there are any two of the ` characters in the following formation ``, delete the second one and skip to the next line.
3) If there are three of the ` characters in the following formation ```, keep the first one, delete the second 2 and then skip to the next line.

Thanks!
VBBRettAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
What is your question?
0
Steven CarnahanNetwork ManagerCommented:
It sounds like a search/replace?
0
VBBRettAuthor Commented:
Oh, my question is, how do I take each line of text, read it, and add a break point after each ` character?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Mike TomlinsonMiddle School Assistant TeacherCommented:
"If there are three of the ` characters in the following formation ```, keep the first one, delete the second 2"

How would you know in the end result, which ` was actually deleted?!

Sounds like homework to me...
0
VBBRettAuthor Commented:
Never Mind, I will figure it out.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
If it's not homework then say so and we'll provide some code.

If it is, then post what you've got and we'll guide.

Either way; doesn't matter to me.  I just thought the requirement was specific, yet pointless...thus my assumption about it being homework.  =)

In any case, can there be more than three in a row?

What if there are five? `````
Would that change to four ```` then?
0
VBBRettAuthor Commented:
LOL, it's not homework..I've been done with school for over 12 years.  I think a way of catching text.

string line = null;

using (var reader in new StreamReader(filename))
{
  while ((line = reader.ReadLine()) != null))
  {
   }
}
0
VBBRettAuthor Commented:
using (var reader in new StreamReader(filename))
{
  while ((line = reader.ReadLine()) != null))
  {
      if (line.Contains(texttofind))
       {
        }
   }
}
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Those should work for reading.

You'll have to check for the largest to the smallest, otherwise you'll get a false positive.  For instance, if the line has ``` it will return true if you check for a single `...but you would end up using the wrong rule.
0
Michael FowlerSolutions ConsultantCommented:
Use regular expressions. This enables you to allow for any number of back ticks
using (var reader in new StreamReader(filename) {
  while ((line = reader.ReadLine()) != null)) {
      line = Regex.Replace(line, "`+", "`\r\n")
   }
}

Open in new window

Michael
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VBBRettAuthor Commented:
Even though this does work for replacing the "`" with one "`", it doesn't properly handle the following "``" and this "``".  How am I supposed to handle multiple ' marks when they come up?
0
Michael FowlerSolutions ConsultantCommented:
My example finds 1 or more back ticks and replaces it with a single back tick followed by a line break. What exactly is it doing that doesn't meet your needs?
Michael
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.