在ABAP中的给定索引处获取UTF-16代码单元

我想在 ABAP 中的给定索引处获取 UTF-16 代码单元。

Same can be done in JavaScript with charCodeAt().

For example "d".charCodeAt(); will give back 100.

Is there a similar functionality in ABAP?

回答

This can be done with class CL_ABAP_CONV_OUT_CE

DATA(lo_converter) = cl_abap_conv_out_ce=>create( encoding = '4103' ). "Litte Endian

TRY.
    CALL METHOD lo_converter->convert
      EXPORTING
        data   = 'a'
        n      = 1
      IMPORTING
        buffer = DATA(lv_buffer). "lv_buffer will 0061
CATCH ...

ENDTRY.

Codepage 4102 is for UTF-16 Big endian.

It is possible to encode not just a single character, but a string as well:

      EXPORTING
        data   = 'abc'
        n      = 3

"n" always stands for the length of the string you want to be encoded. It could be less, than than the actual length of the string.

  • I think `4103` is little endian and `4102` is big endian.

以上是在ABAP中的给定索引处获取UTF-16代码单元的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>