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

  • SEARCH
  • Home
  • 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 3798804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:37:55+00:00 2026-05-19T13:37:55+00:00

( Similar questions to this have been asked on StackOverflow, but not exactly this.

  • 0

(Similar questions to this have been asked on StackOverflow, but not exactly this. The nearest is probably “javascript how to convert unicode string to ascii“, where there is already the remark “this has to be a dup[licate]”. I have read some similar posts, but they don’t answer my specific question. I’ve looked on the very good W3Schools site, and have also Googled it, but not found the answer that way either. So any hints here would be very much appreciated.)


I have an array of bytes being passed to a piece of JavaScript. In the JavaScript the data arrives in a string. I do not know the mechanism of transfer, as it’s from a 3rd-party application. I do not know even whether the string is “wide” or “narrow”.

In my JavaScript, I have some code like b = str.charCodeAt(pos);.

My problem is that a byte value such as 0x86 = 134 is coming through as character 0x2020 = 8224. This seems to be because my original byte interpreted as a Latin-1 (probably) ‘dagger’ character, and is then being translated to the equivalent Unicode code-point. (The problem may or may not be JavaScript’s ‘fault’.) Similar problems occur with other values, although the ranges 0x00..0x7F and 0xA0..0xFF seem to be fine, but most values from 0x80..0x9F are affected, in each case the value seems to be the Unicode for the original Latin-1.

Another observation is that the length of the string is what I’d expect for narrow string if the length was measured in bytes. (On the other hand, if length returns a value in abstract characters, this doesn’t tell me anything.)

So, in JavaScript, is there a way at getting at the ‘raw’ bytes in a string, or getting a Latin-1 or ASCII character code directly, or of converting between character encodings, or defining the default encoding?

I could write my own mapping, but I’d rather not. I expect that is what I’ll end up doing, but that has the feel of a kludge on a kludge.

I’m also looking into whether there’s anything I can adjust in the calling application (as it could be passing the data as a wide string, although I doubt it).

Either way, though, I’d be interested in whether there is a simple JavaScript solution, or to understand why there isn’t.

(If the incoming data was character data, having Unicode dealt with so automatically would be great. But it’s not, it’s just a binary data stream.)

Thanks.

  • 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-19T13:37:56+00:00Added an answer on May 19, 2026 at 1:37 pm

    There is no such thing as the raw bytes in a String. The EcmaScript spec defines a string as a sequence of UTF-16 code-units. That is the most fine-grained representation exposed by any interpreter have ever encountered.

    On the browser there are no encoding libraries. You have to roll your own if you are trying to represent a byte array as a string and want to reencode it.

    If your string already happens to be valid ASCII, then you can get the numeric value of a code unit by using the charCodeAt method.

    "\n".charCodeAt(0) === 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Similar questions have been asked but not quite similar enough! Given this structure: <p
Similar questions to this one have been asked but none seem to address my
Questions similar to this have been asked all over, but I haven't been able
I know similar questions have been asked many times befor, but I think this
I know similar questions have been asked before, but still things are not clear
Similar questions have been asked, but I have not come across an easy-to-do-it way
Similar questions to this have been asked a number of times here, but none
I know similar questions have been asked before but i think this is slightly
Similar questions have been asked, but nothing exactly like mine, so here goes. We
I know there have been some similar questions to this, but they haven't helped

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.