CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2008
    Posts
    61

    IsTextUnicode() Function ?

    hi all,
    I need a source code that uses IsUnicodeText() function, In fact I want to know how can I use this useful function in my Program ...
    can anyone give me a sample for this purpose ?
    Thanks all

    - escap3

  2. #2
    Join Date
    Jun 2005
    Posts
    1,255

    Smile Re: IsTextUnicode() Function ?

    Here is an example (not tested)
    Code:
    char foo[1000];
    int t;
    t = IS_TEXT_UNICODE_ASCII16;
    If (IsTextUnicode(foo, 1000, &t)
       // Unicode Ascii16
       ...
    else
       // Not Unicode Ascii16
    BTW, are you sure it is a "useful function"?
    See "Why I don't like the IsTextUnicode API" at http://blogs.msdn.com/michkap/archiv...30/363308.aspx

  3. #3
    Join Date
    May 2002
    Posts
    1,435

    Re: IsTextUnicode() Function ?

    Please read the blog post provided by olivthill before going any further with your development.

    Normally, a program will be compiled for UNICODE or MBCS and all strings will be one or the other so there is no need to use a function like this.

    IsTextUnicode() would typically be used when you have a BYTE buffer of unknown format that was generated outside of your program and you want to determine if it contains UNICODE text.

    However, before you use this function I would strongly urge you (again, as olivthill did) to consider whether or not this function is really useful. Perhaps if you told us why you think you need it we could offer better advice.

  4. #4
    Join Date
    Jul 2008
    Posts
    61

    Re: IsTextUnicode() Function ?

    hey, thanks from your advices, yeap I know that this function maybe return a wrong value & it's not a reliable function .
    and as one of you said, in normally, strings in a program will be compiled for UNICODE standard (UTF-16) .
    but, suppose a program like notepad .
    when you write some text in it, you can save it as the standard you want .
    maybe you want to save it as ASCII & then you want to open a text file .
    a program like notepad should be check the String format of the file and a Function like IsTextUnicode() need in the program to recognize the String Format of the file my program also need a function to check the String format of a specific file .
    do you know any other idea regardless of using IsTextUnicode() for this matter ?
    is there any way for recognizing the String Format of a specific file when you want to Open a file in your program ?

    anyone can help about this ?

    thanks

    -escap3
    Last edited by escap3; July 19th, 2008 at 02:33 PM.

  5. #5
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: IsTextUnicode() Function ?

    If a plain text file is a Unicode plain text file, then it should be prefixed with a byte order mark. See "Byte Order Mark" at http://msdn.microsoft.com/en-us/libr...29(VS.85).aspx

    So, the logic of your program might be:
    1. check for presence of a byte order mark (BOM). If not present, then the file is ASCII
    2. If BOM is present, then the file is Unicode. Check for its format, to determine exactly the the precise type of Unicode encoding

  6. #6
    Join Date
    Feb 2011
    Posts
    1

    Re: IsTextUnicode() Function ?

    Sometimes text files in unicode go without BOM. So IsTextUnicode() is essential for the software which should import any user text files.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured