Dear all
CString aStr="Learning ¤¤¤å"; //a mixed English and Chinese string
Extracting each Chinese Character from The String and assign it to a UINT data type.
UINT aWord = ????
i use _MBCS not unicode
can someone tell me how?
Printable View
Dear all
CString aStr="Learning ¤¤¤å"; //a mixed English and Chinese string
Extracting each Chinese Character from The String and assign it to a UINT data type.
UINT aWord = ????
i use _MBCS not unicode
can someone tell me how?
For Big5 Chinese Character (2-byte char), the first byte is within a range (about 0xA1 to 0xFE). If it is in the range, then you have to extract both the current and next byte. Therefore, you combine the 2 extracted bytes to form back a Chinese Character.
Thanks for your reply.
for extracting currenct byte, do you mean to use the IsDBCSLeadByte()?
I really donot how to extract both the current and next byte, and combine the 2 extracted bytes to form back a Chinese Character?
I hope the following code can help.
Code:CString aStr = "Learning ¤¤¤å";
char cChinese[3];
cChinese[2] = '\0';
int i = 0;
while (i<aStr.GetLength()) {
if ((byte)aStr[i] >= 0xA1 && (byte)aStr[i] <=0xFE) {
cChinese[0] = aStr[i];
cChinese[1] = aStr[i+1];
AfxMessageBox(cChinese);
++i;
}
++i;
}
Thanks
code:--------------------------------------------------------------------------------
CString aStr = "Learning ¤¤¤å";
char cChinese[3];
cChinese[2] = '\0';
int i = 0;
while (i<aStr.GetLength()) {
if ((byte)aStr[i] >= 0xA1 && (byte)aStr[i] <=0xFE) {
cChinese[0] = aStr[i];
cChinese[1] = aStr[i+1];
AfxMessageBox(cChinese);
UINT aWord = cChinese // How to assign a Char to UINT
++i;
}
++i;
}
--------------------------------------------------------------------------------
Actually a UINT is a 4-byte variable while a Chinese Character is 2-byte. So how do you want to assign to the UINT?
HI
DWORD GetGlyphOutline(
HDC hdc, // handle to device context
UINT uChar, // character to query
UINT uFormat, // format of data to return
LPGLYPHMETRICS lpgm, // pointer to structure for metrics
DWORD cbBuffer, // size of buffer for data
LPVOID lpvBuffer, // pointer to buffer for data
CONST MAT2 *lpmat2 // pointer to transformation matrix structure
);
I use GetGlyphOutline function to retrieve the outline for a character in the True type font, so it need to use "UINT".
It works ok when I assign a single Chinese Character to UINT.
UINT aWord ='¤¤'; // works ok
But for my program, the user will input a String; therefore, i have to extracte each character from the String and run GetGlyphOutline function for each character to get its outline.
Code:CString aStr = "Learning ¤¤¤å";
int i = 0;
while (i<aStr.GetLength()) {
if ((byte)aStr[i] >= 0xA1 && (byte)aStr[i] <=0xFE) {
UINT aWord = 0;
((char*)&aWord)[0] = aStr[i+1];
((char*)&aWord)[1] = aStr[i];
++i;
}
++i;
}
I am really thank you for help me to solve this problem. and i found another way to assign a Chinese Character to UINT
What do you think about this method?Code:CString aStr = "Learning ¤¤¤å";
int i = 0;
while (i<aStr.GetLength()) {
if ((byte)aStr[i] >= 0xA1 && (byte)aStr[i] <=0xFE) {
int k1=(byte)aStr [i];
int k2=(byte)aStr [i+1];
UINT aWord=(k1*256)+k2; //(HiByte * 256 + LoByte)
++i;
}
++i;
}
Either yours and mine can solve the problem. :-)
In my opinion, yours is better.