1

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

9
  • 2
    Unicode is 16/32 bit - making it 7 bit is not decompression - it's compression. Commented Nov 26, 2009 at 8:45
  • 3
    If you were to call it compression then it's lossy compression, at best. Commented Nov 26, 2009 at 8:55
  • Do you need to "decompress" it, or do you want functions to print it and play with it? Commented Nov 26, 2009 at 9:08
  • Unicode is actually 20 bits; UTF-16 is a 16 bits encoding and UTF-32 a (trivial) 32 bits encoding. Commented Nov 26, 2009 at 9:40
  • yes i need function to decompress it in c++ Commented Nov 27, 2009 at 11:13

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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()); } 

5 Comments

This allows you to write to UTF-7, the string can be in any encoding i believe
NOTE: If there are some characters in the string that is not supppored by UTF-7, it will be lost
Looks rather more Java than C++ to me.
@Kylotan, I was thinking it looked more like C#, but same point: OP wanted a C++ answer.
@Xander: UTF-7 is a Unicode encoding, like the UTF-16 used by .Net. Now there are characters outside of Unicode (Klingon for instance) but you can't lose those by converting between different Unicode representations.
0

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

Link to g_str_to_ascii() code

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.