VBBRett
asked on
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!
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!
What is your question?
It sounds like a search/replace?
ASKER
Oh, my question is, how do I take each line of text, read it, and add a break point after each ` character?
"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...
How would you know in the end result, which ` was actually deleted?!
Sounds like homework to me...
ASKER
Never Mind, I will figure it out.
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?
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?
ASKER
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))
{
}
}
string line = null;
using (var reader in new StreamReader(filename))
{
while ((line = reader.ReadLine()) != null))
{
}
}
ASKER
using (var reader in new StreamReader(filename))
{
while ((line = reader.ReadLine()) != null))
{
if (line.Contains(texttofind) )
{
}
}
}
{
while ((line = reader.ReadLine()) != null))
{
if (line.Contains(texttofind)
{
}
}
}
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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
Michael