Results 1 to 2 of 2

Thread: CString to *char (Unicode to ASCII)

  1. #1
    Senior Member
    Join Date
    Jan 2008
    Location
    Some where on the earth.
    Posts
    106


    -"-

    นั่งเขียน VC++ อยู่หา function ในการเปลียน CString จาก Unicode เป็น string ที่อยู่ในรูป ASCII ไม่เจอ ขัดใจเลยเขียนเอง
    แต่ออกมาเป็น ASM นะครับ เพราะเท่าที่ดู ทำงานได้เร็วและกินเนิ้อที่น้่อยกว่า ใช้ GetAt() แน่ๆ

    วิธีการใช้งานคือ

    void UnicodeToAscii(char* Ascii_Data, CString UNICODE_Data, int Str_Length)
    โดย รับ parameter 3 ตัวคือ
    1. pointer ของ array char ที่เราต้องการนำค่ามาใส่
    2. pointer ของ CString ที่ต้องการเปลี่ยน
    3. ความยาวของ CString

    และนี่คือ code ครับ

    [hide=5]

    [code]
    void UnicodeToAscii(char* Ascii_Data ,CString UNICODE_Data,int Str_Length){
    <div align="center">"Hacking isn’t about helping the security industry, which leeches from Hackers."</div>

    <div align="center">http://img397.imageshack.us/img397/159/cwhbannerzl0.gif</div>

  2. #2
    Senior Member
    Join Date
    Jul 2004
    Location
    Bangkok
    Posts
    187


    เอ่อ เข้าใจอะไรผิดหรือป่าว ปกติแล้ว CString จะเก็บ TCHAR ซึ่ง TCHAR จะสามารถเป็นได้ทั้ง unicode และ ascii ขึ้นอยู่กับว่า compile เป็นแบบไหน โดยการกำหนด preprocessor (Project -> Settings)

    ถ้าต้องการให้เป็น unicode ก็ define _UNICODE ถ้าไม่มีก็จะเป็น ascii

    Code:
    CString str = _T("Test String"); // use macro _T for assign tchar string
    LPCTSTR szString = (LPCTSTR) str;
    แต่ถ้าอยากจะ convert Unicode -> Ascii หรือ Ascii-> Unicode ก็สามารถทำได้ไม่ยากดัง code ข้างล่าง
    **Hidden Content: To see this hidden content your post count must be 1 or greater.**

Similar Threads

  1. Replies: 0
    Last Post: 09-01-2009, 12:11 AM
  2. Replies: 0
    Last Post: 19-10-2008, 07:02 AM
  3. Convert CString to char*
    By asylu3 in forum C/C++,C#,VC++,MFC,Win32
    Replies: 1
    Last Post: 04-02-2005, 02:32 PM
  4. Convert integer to character (int to char)
    By ar3s in forum C/C++,C#,VC++,MFC,Win32
    Replies: 0
    Last Post: 16-12-2003, 03:25 AM
  5. How to use CString in VC++
    By asylu3 in forum C/C++,C#,VC++,MFC,Win32
    Replies: 0
    Last Post: 26-07-2003, 09:41 PM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •