While learning with books sometimes i copy some code from pdf, to test it.
This tiny exe was suppose to change ‘ ’ “ ” to ' or "
and it work fine, but only if tested *.cs file is opened manually before I debug my methods.
Otherwise it's not working. When code paste into concerned file directly, and closed, without opening once again The Replace method return "Unexpected character ?"
I dont understand the probleme, since File.ReadAllText already open and close the file.
using System;
using System.Collections.Generic;
using System.IO;
class Test
{
public static void Main()
{
string path = Directory.GetCurrentDirectory();
string[] csfiles = Directory.GetFiles(path, "*.cs");
foreach (var item in csfiles)
{
string text = File.ReadAllText(item);
text = text.Replace("‘", "\'")
.Replace("’", "\'")
.Replace("“", "\"")
.Replace("”", "\"");
File.WriteAllText(item, text);
}
}
}