Reputation: 109
In my project, I need to convert the string that contains the superscript - m² to the string m2.
My project accepts unit of measure which includes meter square (m²) or meter cube (m³). And I need to convert the superscripts to a normal integer or string in order to further process the input data. However, at this moment am unable find any thing in C++ that does this for me.
The application is in C++ and we are using CComBSTR to store the string.
The ideal output would be m2 for m² and m3 for m³ and so on...
Any suggestions
Upvotes: 3
Views: 891
Reputation: 179991
A CComBSTR
is just a wrapper for a BSTR
. That in turn is a WCHAR*
, which maps to C++ type wchar_t*
. Since you're on Windows, you have to know that WCHAR
is UTF-16.
That means you need to look for wchar_t(0x00B2)
and wchar_t(0x00B3)
. std::find
can do that, just pass it the begin and end of your BSTR
.
Upvotes: 2
Reputation: 5230
I suspect the key point is the character encoding. A superscript 2 is not an ascii char. They have dedicated unicode chars (see http://en.wikipedia.org/wiki/Superscripts_and_Subscripts, with values in range 0x207x, except 2 and 3) and they are typically encoded with 16 bits. If you have a std::string then a character then they are probably encoded in UTF-8, which means more than one char per character (see http://en.wikipedia.org/wiki/UTF-8).
There is a lot to read, but at the end it's quite easy. You just need to search for a substring (che UTF-8 of superscript 2 and 3)
Upvotes: 0