ABAP 字元與ASCII互轉

2021-05-12 10:12:48 字數 1644 閱讀 6898

方法一:

report demotest.

* 1.將字元轉成ascii code

data : c value 'a'.

field-symbols : type x.

data : rn type i.

assign c to casting.

move to rn.

write rn.

* 2. 將ascii code轉成字元

data : i type i value 66.

data : x type x.

field-symbols : type c.

move i to x.

assign x to casting type c.

move to c.

write c.

方法二:

字元轉ascii

url_ascii_code_get

特點,根據這個演算法可以中文轉ascii

互轉hr_kr_string_to_xstring   (應該就是char-》raw或者bin的二進位制)

hr_kr_xstring_to_string

so_solitab_to_solixtab

so_solixtab_to_solitab

互轉report sapmzts3.

data: l_s type string value 'a'.

data: l_s1 type xstring.

data: lr_conv_ci type ref to cl_rpe_convert .

create object lr_conv_ci.

l_s1 = '42'.

call method lr_conv_ci->xstring_to_string

exporting

input = l_s1

importing

output = l_s.

write l_s.

call method lr_conv_ci->string_to_xstring

exporting

input = l_s

importing

output = l_s1.

write l_s1.

示例:report   z_barry_test_ascii.

data: str type string ,

xstr type xstring,

l_con type ref to cl_rpe_convert .

start-of-selection.

create object l_con.

call method l_con->string_to_xstring

exporting

input   = 'abc'

importing

output = xstr.

call method l_con->xstring_to_string

exporting

input   = '4261727279'

importing

output = str.

write / :   xstr ,str.

ASCII與中文互轉

我們在開發使時常會用到資源檔案,這可能是為了多語言 國際化的需要,也可能是使用了國外開源專案的原因,這就需要中文轉ascii將中文轉換為 ascii 編碼,或者將 ascii 轉換為中文,那麼我們就可以使用 jdk 自帶的轉換工具 native2ascii for example no1 中文轉換為...

ASCII與中文互轉

我們在開發使時常會用到資源檔案,這可能是為了多語言 國際化的需要,也可能是使用了國外開源專案的原因,這就需要中文轉ascii將中文轉換為ascii 編碼,或者將 ascii 轉換為中文,那麼我們就可以使用 jdk 自帶的轉換工具 native2ascii for example no1 中文轉換為 ...

js字元與ASCII碼互轉的方法

在開發過程中,我遇到的需求為輸出選擇題的題目。這樣就需要輸出a b c d e等選項。我們可以定義乙個字元陣列解決。也可以利用字元間的ascii碼的關係更簡單地解決。解決示例如下 let letter a for let of questionattrcopys else.letter letter...