|
-
September 17th, 2003, 03:21 AM
#1
Extracting Chinese Character from a CString
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?
-
September 17th, 2003, 04:26 AM
#2
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.
In Chinese Proverb, "Teaching the poor fishing is better than giving fish to them".
-
September 17th, 2003, 05:09 AM
#3
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?
Last edited by wow9999; September 17th, 2003 at 05:14 AM.
-
September 17th, 2003, 09:22 AM
#4
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;
}
In Chinese Proverb, "Teaching the poor fishing is better than giving fish to them".
-
September 17th, 2003, 08:03 PM
#5
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;
}
--------------------------------------------------------------------------------
Last edited by wow9999; September 17th, 2003 at 08:33 PM.
-
September 17th, 2003, 10:42 PM
#6
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?
In Chinese Proverb, "Teaching the poor fishing is better than giving fish to them".
-
September 17th, 2003, 10:59 PM
#7
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.
-
September 18th, 2003, 03:47 AM
#8
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;
}
In Chinese Proverb, "Teaching the poor fishing is better than giving fish to them".
-
September 18th, 2003, 04:54 AM
#9
I am really thank you for help me to solve this problem. and i found another way to assign a Chinese Character to UINT
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;
}
What do you think about this method?
-
September 18th, 2003, 05:22 AM
#10
Either yours and mine can solve the problem. :-)
In my opinion, yours is better.
In Chinese Proverb, "Teaching the poor fishing is better than giving fish to them".
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|