简体   繁体   中英

Code to convert Unicode to ASCII

I am looking for code for convert unicode to 7bit ASCII. Any suggestions?

If encoded with utf-8, it is the same for both ascii and unicode as ascii is a subset of unicode. See the example in RFC 2044

A simple example below:

        try
        {
            System.IO.TextWriter writeFile = new StreamWriter("c:\\textwriter.txt",false,Encoding.UTF7);
            writeFile.WriteLine("example text here");
            writeFile.Flush();
            writeFile.Close();
            writeFile = null;
        }
        catch (IOException ex)
        {
            MessageBox.Show(ex.ToString());
        }

I'd recommend to adapt the code from glib C function g_str_to_ascii() to C++:

Link to g_str_to_ascii() code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM