I have a large txt file, that is saved into one line. I can not show show due to privacy, but it would include some tildes throughout.

As far as code is, here is the method that I have written currently to actually look in an entire directory, and then proceed to linebreak on each tilde. Right now, it linebreaks on the first tilde and then stops so that there is 2 lines. I deleted the filepath directory, because as stated before, there are privacy concerns.

Thank you for all suggestions.

        public static void LineReturnTilde() //ReplaceAsterik
    {
        // where to start your directory walk

        var directoryToTraverse = @"\\";

        // what files to open

        var fileTypeToOpen = "*.820";

        // what to look for
        var patternToMatch = @"\~";

        var regExp = new Regex(patternToMatch);

        // the new content

        var patternToReplace = "~\r\n";

        // get all the files we want and loop through them to replace

        foreach (var file in Directory.GetFiles(directoryToTraverse, fileTypeToOpen, SearchOption.AllDirectories))
        {
            // open, replace, overwrite

                var contents = File.ReadAllText(file);

                var newContent = regExp.Replace(contents, patternToReplace);

                File.WriteAllText(file, newContent);

        }

    }
1

There are 1 answers

0
Cels On

So, turns out it ended up working after all. I read in another forum you may encounter weird errors like that if you don't have full privileges on a network drive. I put the files into a directory on my local machine and it worked flawlessly.