Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6635841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:06:27+00:00 2026-05-25T23:06:27+00:00

Say I have a function that receives a byte array: void fcn(byte* data) {

  • 0

Say I have a function that receives a byte array:

void fcn(byte* data)
{
...
}

Does anyone know a reliable way for fcn() to determine if data is an ANSI string or a Unicode string?

Note that I’m intentionally NOT passing a length arg, all I receive is the pointer to the array. A length arg would be a great help, but I don’t receive it, so I must do without.

This article mentions an OLE API that apparently does it, but of course they don’t tell you WHICH api function: http://support.microsoft.com/kb/138142

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:06:28+00:00Added an answer on May 25, 2026 at 11:06 pm

    First, a word on terminology. There is no such thing as an ANSI string; there are ASCII strings, which represents a character encoding. ASCII was developed by ANSI, but they’re not interchangable.

    Also, there is no such thing as a Unicode string. There are Unicode encodings, but those are only a part of Unicode itself.

    I will assume that by “Unicode string” you mean “UTF-8 encoded codepoint sequence.” And by ANSI string, I’ll assume you mean ASCII.

    If so, then every ASCII string is also a UTF-8 string, by the definition of UTF-8’s encoding. ASCII only defines characters up to 0x7F, and all UTF-8 code units (bytes) up to 0x7F mean the same thing as they do under ASCII.

    Therefore, your concern would be for the other 128 possible values. That is… complicated.

    The only reason you would ask this question is if you have no control over the encoding of the string input. And therefore, the problem is that ASCII and UTF-8 are not the only possible choices.

    There’s Latin-1, for example. There are many strings out there that are encoded in Latin-1, which takes the other 128 bytes that ASCII doesn’t use and defines characters for them. That’s bad, because those other 128 bytes will conflict with UTF-8’s encoding.

    There are also code pages. Many strings were encoded against a particular code page; this is particularly so on Windows. Decoding them requires knowing what codepage you’re working on.

    If you are in a situation where you are certain that a string is either ASCII (7-bit, with the high bit always 0) or UTF-8, then you can make the determination easily. Either the string is ASCII (and therefore also UTF-8), or one or more of the bytes will have the high bit set to 1. In which case, you must use UTF-8 decoding logic.

    Unless you are truly certain of that these are the only possibilities, you are going to need to do a bit more. You can validate the data by trying to run it through a UTF-8 decoder. If it runs into an invalid code unit sequence, then you know it isn’t UTF-8. The problem is that it is theoretically possible to create a Latin-1 string that is technically valid UTF-8. You’re kinda screwed at that point. The same goes for code page-based strings.

    Ultimately, if you don’t know what encoding the string is, there’s no guarantee you can display it properly. That’s why it’s important to know where your strings come from and what they mean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
Let's say you have a function that returns a date: Date myFunc(paramA, paramB){ //conditionally
Say I have a Python function that returns multiple values in a tuple: def
Say I have a function foo that I want to call n times. In
Say I have a function func(i) that creates an object for an integer i,
Let's say that I have an Erlang function, with spec. -spec foo(integer(), string()) ->
Many people have argued about function size. They say that functions in general should
Using JavaScript, say I have a function X, and in that function an object
Say I have a function that takes a function pointer: int funct(double (*f)(double)); And
Say I have a singleton-ish, factory-ish, reflection-ish class that receives some input, and spits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.