You think that Windows-1252 supports the special characters listed above (see the Wikipedia entry for the full list).
using (var writer = new StreamWriter(destination, true, Encoding.GetEncoding(1252))) { writer.WriteLine(source); }
In my test application using the above code, this result was obtained:
Look at the cool letters I can make: Γ₯, Γ¦, and ΓΈ!
No question marks found. Do you set the encoding when you read it using StreamReader ?
EDIT: You should simply use Encoding.Convert to convert the VCF UTF-8 file to Windows-1252. No need for Regex.Replace . Here's how I do it:
// You might want to think of a better method name. public string ConvertUTF8ToWin1252(string source) { Encoding utf8 = new UTF8Encoding(); Encoding win1252 = Encoding.GetEncoding(1252); byte[] input = source.ToUTF8ByteArray(); // Note the use of my extension method byte[] output = Encoding.Convert(utf8, win1252, input); return win1252.GetString(output); }
And here is what my extension method looks like:
public static class StringHelper {
Also, you probably want to add using to your ReadFile and WriteFile methods.
Kredns
source share