Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Read a character string

Former Member
0 Likes
979

I trying to read a character string which has #'s in it. I need to replace each of these #'s with spaces. None of the standard string functions help in this regard.

Is there a way that I can read character by character and replace the #'s with spaces.

Thanks in advance

7 REPLIES 7
Read only

former_member194669
Active Contributor
0 Likes
811

REPLACE '#' WITH space INTO from_string.

or

replace all occurences of '#' in from_string with ''.

aRs

Read only

ferry_lianto
Active Contributor
0 Likes
811

Hi,

You can also use TRANSLATE statement.


TRANSLATE WA_TEXT USING '# '.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
811

Hi Vamseedhar,

I think # representing Horizontal tabl and it is equivalent to CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

Try with the following statement.

replace all occurrences of

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB in str with space.

Thanks,

Vinay

Read only

Former Member
0 Likes
811

Hi,

You shoud user the TRANSLATE command. DO NOT USE REPLACE command. If you have character "#" at the end of the string, REPLACE command thinks it as a "return command" and does not replace it. Please check this code.

*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
DATA: string(10) TYPE c VALUE '123#5678#'.

DATA: string1(10) TYPE c,
      string2(10) TYPE c,

WRITE:/0 'Original String :',
       20 string.

string1 = string.
REPLACE '#' WITH space INTO string1.
WRITE:/0 'REPLACE String :',
       20 string1.

string2 = string.
TRANSLATE string2 USING '# '.
WRITE:/0 'TRANSLATE String :',
       20 string2.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*

Regards,

RS

Read only

Former Member
0 Likes
811

Hi!

data: c(30) value 'AAXZC#D#GH'.

translate c using '# '.

condense c.

WRITE C.

Reward points if it helps.

Regards,

Neha Bansal.

Read only

Former Member
0 Likes
811

<b>The character '#' can be a Horizontal tab or a new line or a Vertical tab...

Those '#' are special characters to indicates new line or tab. You need to use the abap objects CL_ABAP_CHAR_UTILITIES to fix this issue.</b>

try with all the threee...

define a constant..

constants :

C_HTAB value CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,

C_VTAB value CL_ABAP_CHAR_UTILITIES=>VERTICAL_TAB,

C_NLINE value CL_ABAP_CHAR_UTILITIES=>NEWLINE.

replace all occurrences of C_HTAB in w_string with space.

replace all occurrences of C_VTAB in w_string with space.

replace all occurrences of C_NLINE in w_string with space.

<b><u>I am sure.. one of the above three will work.</u></b>

plz do remember to close the thread when ur problem gets solved..

reward all helpful answers,

sai ramesh

Read only

Former Member
0 Likes
811

hi,

DATA: STRING(80).

STRING = 'Variable: The variable # is substituted later.'.
REPLACE '#' WITH ' ' INTO STRING.
WRITE / STRING.

Rgds

Reshma