首页 > 代码库 > 字符串处理
字符串处理
DATA: a1(5) TYPE c,
a2(2) TYPE c,
a3(2) TYPE c,
a4(2) TYPE c,
a5(20) TYPE c,
a9(2) TYPE c.
a1 = ‘AB‘.
a2 = ‘CD‘.
a3 = ‘EF‘.
a4 = ‘GH‘.
a9 = ‘+‘.
CONCATENATE a1 a2 a3 a4 INTO a5. "合并时候去掉空格
WRITE a5.
CONCATENATE a1 a2 a3 a4 INTO a5 SEPARATED BY a9. "合并时候加上指定字符
WRITE / a5.
CONCATENATE a1 a2 a3 a4 INTO a5 RESPECTING BLANKS. "合并时候保留前后空格
WRITE / a5.
SKIP.
ULINE.
" 拆分字符串
DATA: c1(5) TYPE c,
c2(2) TYPE c,
c3(3) TYPE c,
c4(2) TYPE c,
c5(20) TYPE c VALUE ‘11 * 22 * 33 * 44‘,
c9(2) TYPE c.
c9 = ‘*‘.
WRITE / c5.
SPLIT c5 AT c9 INTO c1 c2 c3 c4.
WRITE: / c1, c2, c3, c4.
SKIP.
ULINE.
"替换字符串
DATA: b1(2) TYPE c,
b2(2) TYPE c,
b3(2) TYPE c,
b4(2) TYPE c,
b5(20) TYPE c,
b9(2) TYPE c.
b1 = ‘AB‘.
b2 = ‘CD‘.
b3 = ‘EF ‘.
b4 = ‘GH‘.
b9 = ‘+‘.
WRITE: / b1,b2,b3,b4.
REPLACE b3 WITH b1 INTO b3 LENGTH 2. "把字符串b3中的b3替换成b1,如果指定2,就是指定了替换的长度。
" 如果替换成功,则SY-SUBRC设置成
WRITE: / b1, b2,b3,b4.
字符串处理