UTF16十六进制文本

UTF16十六进制文本

本文介绍了UTF16十六进制文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有UTF-16十六进制表示形式,例如 0633064406270645,阿拉伯语为سلام。

I have UTF-16 hex representation such as "0633064406270645" which is "سلام" in Arabic language.

我想将其转换为等效的文本。在PostgreSQL中有直接的方法吗?

I would like to convert it to its text equivalent. Is there a straight way to do that in PostgreSQL?

我可以像下面这样转换UTF代码点;不幸的是,似乎不支持UTF16。关于如何在PostgreSQL中进行操作的任何想法,最坏的情况下我将编写一个函数?

I can convert the UTF code point like below; unfortunately it seems UTF16 is not supported. Any ideas on how to do it in PostgreSQL, worst case I will write a function?

SELECT convert_from (decode (E'D8B3D984D8A7D985', 'hex'),'UTF8');

"سلام"

SELECT convert_from (decode (E'0633064406270645', 'hex'),'UTF16');

ERROR:  invalid source encoding name "UTF16"
********** Error **********


推荐答案

是的,Postgres不支持UTF-16。

That's right, Postgres doesn't support UTF-16.

但是,它确实支持:

SELECT U&'\0633\0644\0627\0645'

但请记住 Unicode代码点 UTF-16代码单元仅在。换句话说,如果您有跨多个16位代码单元的UTF-16字符,则需要自己将其转换为相应的代码点。

But keep in mind that Unicode code points and UTF-16 code units are only equivalent in the Basic Multilingual Plane. In other words, if you have any UTF-16 characters which span multiple 16-bit code units, you'll need to translate them to the corresponding code point yourself.

这篇关于UTF16十六进制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 09:38