2021 Jun 16 2:32 PM
My requirement is to remove a defined 1 char (on a known position) from string and replace it with SPACE. The below code is working fine, but it is replacing the char with 'x'.
DATA: text1 TYPE string.
text1 = 'abcdXefgh'.
REPLACE SECTION OFFSET 4 LENGTH 1 OF:
text1 WITH 'x'.
WRITE: / text1.
The below code is not working fine since it is removing also the SPACE.
DATA: text1 TYPE string.
text1 = 'abcdXefgh'.
REPLACE SECTION OFFSET 4 LENGTH 1 OF:
text1 WITH space.
WRITE: / text1.
Whats the best way to remove the char and replace it with space?
2021 Jun 16 2:52 PM
Another possible solution (use backquotes to indicate a true space character, because in lots of places SPACE is like a null-length string, not a space character - I like my clear explanations 🙂 😞
REPLACE SECTION OFFSET 4 LENGTH 1 OF:
text1 WITH ` `.
My requirement is to remove a defined 1 char (on a known position) from string and replace it with SPACE. The below code is working fine, but it is replacing the char with 'x'.
DATA: text1 TYPE string.
text1 = 'abcdXefgh'.
REPLACE SECTION OFFSET 4 LENGTH 1 OF:
text1 WITH 'x'.
WRITE: / text1.
The below code is not working fine since it is removing also the SPACE.
DATA: text1 TYPE string.
text1 = 'abcdXefgh'.
REPLACE SECTION OFFSET 4 LENGTH 1 OF:
text1 WITH space.
WRITE: / text1.
Whats the best way to remove the char and replace it with space?
2021 Jun 16 2:40 PM
You have to work with string, not text.
My "not terrible" solution
data(text1) = 'abcdefgh'.
data offset type i value 4.
data size type i value 1.
data(second_offset) = offset + 1.
data(second_size) = strlen( text1 ) - ( offset + 1 ).
data(text2) = |{ text1+0(offset) } { text1+second_offset(second_size) }|.
write text2.
2021 Jun 16 2:46 PM
Another possible easier solution:
DATA(line) = 'abcdef'.
WRITE / line.
line+3(1) = SPACE.
WRITE / line.
2021 Jun 16 2:52 PM
Another possible solution (use backquotes to indicate a true space character, because in lots of places SPACE is like a null-length string, not a space character - I like my clear explanations 🙂 😞
REPLACE SECTION OFFSET 4 LENGTH 1 OF:
text1 WITH ` `.
2021 Jun 16 3:10 PM
Simple and precise solution by Sandra.
You are not the only one to like your explanation, I like it too. :-))