利用正则表达式,简单代码如下:
DATA: lv_str0 TYPE string,
lv_str1 TYPE string,
lv_str2 TYPE string.
lv_str0 = lv_str1 = lv_str2 = ‘AB、¥C中国ABC_美国132’.
” 只保留双字节字符
REPLACE ALL OCCURRENCES OF REGEX ‘[u4e00-u9fa5]’ IN lv_str1 WITH space.
” 只保留单字节字符
REPLACE ALL OCCURRENCES OF REGEX ‘[^x00-xff]’ IN lv_str2 WITH space.
WRITE: ‘原始字符串: ‘, lv_str0,
/ ‘双字字字符: ‘, lv_str1,
/ ‘单字节字符: ‘, lv_str2.
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/20075.html