preciz
This is the string:
"\\376\\377\\0001\\0009\\000 \\0001\\0002\\000 \\0001\\0009\\000 \\000P\\000r\\000o\\000g\\000r\\000a\\000m\\000m\\000f\\000o\\003\\b\\000r\\000d\\000e\\000r\\000u\\000n\\000g\\000 \\0002\\0000\\0002\\0000\\000 \\000-\\000 \\000A\\000n\\000l\\000a\\000g\\000e\\000 \\0002\\000 \\000-\\000 \\000F\\000o\\003\\b\\000r\\000d\\000e\\000r\\000e\\000r\\000g\\000e\\000b\\000n\\000i\\000s\\000s\\000e\\000.\\000d\\000o\\000c\\000x"
That should be converted to: "19 12 19 Programmförderung 2020 - Anlage 2 - Förderergebnisse.docx"
It’s from a PDFs /Info dictionary.
The "\\376\\377" is a BOM (byte order mark) meaning it’s an UTF16 big endian.
Firefox can read it properly and I assume this is the source code they use:
https://github.com/mozilla/pdf.js/blob/50bc4a18e8c564753365d927d5ec6a6d2cce3072/src/display/metadata.js#L37
I did try to replicate this in Elixir but when it gets to the "ö" it breaks into non relevant characters.
What would be the correct way to convert the string?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex











Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
You should check
:unicodemodule for that. It has all functions you will need.malaire
That shown code isn’t enough to decode the string as it doesn’t handle decoding
\\003\\bto UTF16 codepoint0x0308.This could be fixed e.g. by first converting
\\bto\\010, but full solution would need a list of all possible escape codes used in the encoding.preciz
Can you elaborate on the bit why is this escape character used in the string?
malaire
It looks like UTF16 BE bytes in printable ASCII range are represented as ASCII characters (e.g.
Pinstead of\\120), and at least some UTF16 BE bytes in ASCII control character range use the usual escape codes (e.g.\\bmeaning ASCII backspace).So encoding might also be using some other escapes like
\\nfor\\012(line feed) or\\rfor\\015(carriage return).dimitarvp
Does the
pdfinfotool read this data properly btw?I don’t even see how
\0001\0009transcodes to"19". This is not how UTF-16BE does it. Looks to be some other encoding.malaire
String
\\0001\\0009is converted to 4 bytes:\\000is octal encoding for byte0x001means ASCII value of character1, i.e.0x31\\000is octal encoding for byte0x009means ASCII value of character9, i.e.0x39So that is 4 bytes
0x00 0x31 0x00 0x39which is UTF16 BE encoding for"19".dimitarvp
Oh, so as you said some values aren’t exactly UTF-16BE encoded. They are directly their printable equivalents.
Well, that’s still not UTF-16BE per se.
g-andrade
This seems to do it in Erlang:
You can interact with it here.
Unfortunately I wasn’t able to have declare an equivalent literal value in Elixir; but, as long as your string is in the expected format, the same pattern should work.
If, however, the double-backslashes represent actual backslashes in the original string and are not the result of printing / inspecting it, then they’ll need to be unescaped first.
g-andrade
Now, as far as unescaping the string - if needed - this seems to do the trick:
What it does is transform the string into a charlist containing an Erlang “string expression”, which it proceeds to parse - and so I wouldn’t trust it with untrusted input without further investigation.