Write to file out of squares

For my test data, I use the characters:

漢字仮名交じり文 

My code that writes the file is:

 // Create license key file if (!File.Exists(Settings.LicenseFilesLocation + "/" + EmailAddress + "/" + LicenseFileName)) { HttpContext.Current.Response.Write(Name.Normalize()); HttpContext.Current.Response.End(); // UTF-8 StreamWriter License = File.CreateText(Settings.LicenseFilesLocation + "/" + EmailAddress + "/" + LicenseFileName); License.WriteLine("Licensed to: " + Name.Normalize()); License.Flush(); License.Close(); 

As you can see, I print the value before saving it to a file in order to check it, and it prints correctly. However, in the saved text file, when I open it in notepad, it appears as many squares (see screenshot):

enter image description here

When I copy and paste these characters, they are copied and pasted correctly:

 漢字仮名交じり文 

We have many customers who claim that their license file has its name in squares that they don’t like. Our program, which opens and checks this file, also shows its name as squares.

Any ideas how to fix this? When we open our txt license file, we want it to display its name completely without squares.

+4
source share
1 answer

There are two sources to this problem:

  • Your file is not encoded correctly. If you use anything other than ASCII characters, you need to make an informed decision to choose the correct encoding. The fact that copying and pasting works makes me think your encoding is fine, but you still don't know that this is happening behind the scenes.
  • Your editor is trying to display Unicode characters using a font that cannot display them correctly. Not every font supports Unicode. Change the font to a font that can display Unicode characters, and you should be good to go.

EDIT: As a side note, understanding the jokes here will also do you some good.

+7
source

All Articles