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

Replace #

bjorn-henrik_zink
Contributor
0 Likes
767

Hi,

I need some string operations help. I have a field symbol containing <b>a#b#c#</b>. In order to make it work nicely with excel download I would like to replace the # with excel line feeds. The # originates from BSP textedit line feeds. I have tried with <b>replace</b> and <b>translate</b>, but these commands do not find the #s. What should I do?

Thanks in advance.

/Elvez

7 REPLIES 7
Read only

Former Member
0 Likes
714

Hi Elvez,

  1. repsents horizontal tab.

Use CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB instead of #s in your replace statement.

Thanks,

Vinay

Read only

0 Likes
714

Hi Vinaykumar G,

here is my code:

DATA: s(256) type c.

s = l_page->if_bsp_page~to_string( value = <f> ).

REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN s WITH cl_abap_char_utilities=>cr_lf.

It still does not work.

/Elvez

Read only

Former Member
0 Likes
714

Just an example donno if this works for you

data: lv_var(6) type c value 'a#b#c#',

lv_hash type c value '#'.

search lv_var for lv_hash.

if sy-subrc eq 0.

do your processing.

endif.

Thanks,

Santosh

Read only

Former Member
0 Likes
714

Hi,

Here is a sample I wrote in 46C. I am able to use both TRANSLATE and REPLACE successfully to change the characters.

[code]

PARAMETERS: p_string TYPE char20.

DATA: w_string TYPE char20 VALUE '#$'.

WRITE: / 'String before Conversion:', p_string.

TRANSLATE p_string USING w_string.

WRITE: / 'String after TRANSLATE :', p_string.

DO.

REPLACE '$' WITH '@&' INTO p_string.

IF sy-subrc NE 0.

EXIT.

ENDIF.

ENDDO.

WRITE: / 'String after REPLACE :', p_string.

[/code]

Hope this helps.

Sumant.

Read only

Former Member
0 Likes
714

this is working in my system , may be some unicode problems in ur system

REPORT ychatest LINE-SIZE 350.

DATA : v_char(10) VALUE 'a#b#c'.

REPLACE all occurrences of '#' IN v_char WITH space .

CONDENSE v_char.

WRITE : v_char.

check the attributes in the class CL_ABAP_CHAR_UTILITIES and try with some of them

Read only

0 Likes
714

Hi,

the example is working fine stand alone, but when I try to use it in my code it is not working. It seems to be some kind cast issue. Anyone who knows how I can cast the variable in order to make this work?

Thanks.

/Elvez

Read only

bjorn-henrik_zink
Contributor
0 Likes
714

I solved the problem by using CL_ABAP_CHAR_UTILITIES=>NEWLINE instead of #s in my replace statement.

/Elvez