开发者

writing to file comes out squares

开发者 https://www.devze.com 2023-04-02 16:10 出处:网络
For my test data I\'m using the characters: 漢字仮名交じり文 My code that writes a file is: // Create license key file

For my test data I'm using the characters:

漢字仮名交じり文

My code that writes a file is:

// Create license key file
if (!File.Ex开发者_开发知识库ists(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'm printing the value before I save it to file to check it, and it is printing correctly. However in the saved text file when I open it in notepad, it's coming out as lots of squares (see screenshot):

writing to file comes out squares

When I copy and paste these characters they copy and paste correctly as:

漢字仮名交じり文

We are having a lot of customers saying their license file has their name in squares which they don't like. Our software program that opens and verifies this file is also showing their name as squares.

Any ideas how to fix this? We want it so that when customers open their license txt file it shows their name in full without squares.


There are two sources to this problem:

  1. Your file is not encoded correctly. If you are using anything other than ASCII characters, then you need to make the conscious decision to choose the correct encoding. The fact that copying and pasting works makes me think that your encoding is OK, but you still seem unaware of the fact that this is occurring behind the scenes.
  2. Your editor is trying display unicode characters using a font that cannot render them correctly. Not every font supports Unicode. Change the font to a font that can render Unicode characters and you should be good to go.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号