Codings form native UTF8 to windows1250 (iconv)

#1

Hi,

I need make same changes in a text file with windows 1250 encoding. To decoding to UTF-8 I use node-red-contrib-iconv https://flows.nodered.org/node/node-red-contrib-iconv and works fine, but iconv is only to decoding.

The question is how convert back to windows 1250 encoding?

0 Likes

#2

Do you really need to do that? Perhaps you could explain a bit more about what you are trying to achieve.

Most systems, including Windows, all work on Unicode now.

However, if you really want to do it, the simplest way (without other external tools), assuming you are working on Windows or another platform with PowerShell installed is to do something like the following PowerShell command via the exec node:

Get-Content -Path "path/to/your/file/filname.txt" | Out-File -FilePath "wherever/destfile.txt" -Encoding ascii

This will change from unicode to ascii with the current platform's default codepage.

0 Likes

#3

Thank you for your reply,

yes I need it, the file is symbol table from software Step7 developed by Siemens. :de:

This flow run on raspberry.

My reason is now using external js library icon-lite


1 Like

#4

Good find, I didn't spot that with a quick search.

You can, if you wish, require that in your settings.js file under the globals section. Then in a function node, you can simply assign it to a variable var iconv = global.get('iconv') or whatever you called it. Then you can use it within that function node.

0 Likes

#5

It would help if you could share a text file with the original data (windows-1250 encoded). Having a look on the encoding table you will see that many characters will be converted to untranslatable characters, for instance: Á,Â,Ä,Ç,É,Ë,Í,Î,Ú,Ü will be translated to �,�,�,�,�,�,�,�,�,�. In such case, you can imagine what will happen if you try to translate �,�,�,�,�,�,�,�,�,� back to windows-1250. So, my point (not sure if this is your case) is that ,many times, the encoding-decoding back to the same set will not work and this is not a fault of the supporting library.

0 Likes

#6

Hello @Vladimirbuta
I’m the developer of node-red-contrib-iconv and I don’t understand why can’t you do what you want to do.
This node has the ability to encode any type of String and decode any type of Buffer.
Could you please paste your flow or at least the text you want to encode/decode?

2 Likes

#7

Hi machadotiago,

I thought, the converter is only to decoding and for "Coding" is missing. But the the module is universal and everything works fine. Thank you :slight_smile:

2 Likes

#8

Awesome! If you have any suggestion/improvement please let me know.

0 Likes