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

how to remove ## symbol from string.

Former Member
0 Likes
18,990

Hi all,

i am facing a problem to remove ## symbol from string field.

i am using following different ways to remove it , it is not working.

data : text1 TYPE string.

text1 = ' ## He completed ## successful'.

1) REPLACE all occurrences of '##' IN:

text1 WITH ' ' .

2) TRANSLATE text1 using '## '.

3) find is also not working to find the ##.

always subrc = 0.

can any boady help to sole the issue.

Regards,

Kishan

Hi all,

i am facing a problem to remove ## symbol from string field.

i am using following different ways to remove it , it is not working.

data : text1 TYPE string.

text1 = ' ## He completed ## successful'.

1) REPLACE all occurrences of '##' IN:

text1 WITH ' ' .

2) TRANSLATE text1 using '## '.

3) find is also not working to find the ##.

always subrc = 0.

can any boady help to sole the issue.

Regards,

Kishan

22 REPLIES 22
Read only

former_member386202
Active Contributor
0 Likes
5,382

Hi,

Replace # with horizontal tab

  • Local Constants

CONSTANTS : lc_tab(1) TYPE c VALUE "Horizontal Tab

cl_abap_char_utilities=>horizontal_tab.

Regards,

Prashant

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
5,382

This is because ## is actually some garbage character. You should search the forum for CL_ABAP_CHAR_UTILITIES=>CR_LF.

BR,

Suhas

Read only

Former Member
0 Likes
5,382

Hi,

  1. symbol is used for new line carried feed variable. It can be replaced with the following code.

Replace all occurances of CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB in string with space

or

Replace all occurances of CL_ABAP_CHAR_UTILITIES=>NEWLINE in string with space.

Manas M.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
5,382

>

> # symbol is used for new line carried feed variable.

You should re-phrase it as :

  1. symbol is generally used as a replacement character for new line carried feed variable.

BR,

Suhas

Read only

0 Likes
5,382

> Suhas Saha wrote:

> > Kumar Manas Mishra wrote:

> > # symbol is used for new line carried feed variable.

>

> You should re-phrase it as :

>

>> # symbol is generally used as a replacement character for new line carried feed variable.

>

> BR,

> Suhas

Hi Suhas,

That is because Kumar mindlessly copy&pasted it from Abhii's post in this thread:

Kumar's user ID will be deleted for repeatedly violating the forum rules and ignoring moderator requests / warnings.

Cheers,

Julius

Read only

0 Likes
5,382

Not again.

How long will the Guest-o-blaster take for charging up ?

Read only

0 Likes
5,382

Almost unbelievable persistence!

We are warming up the guest-o-blaster and documenting a few things...

Cheers,

Julius

Read only

Former Member
0 Likes
5,382

Hope using REPLACE solve your problem.

Read only

Former Member
0 Likes
5,382

hi,

try this sample code.

data: p_string TYPE string VALUE 'ABC##DE##F#G',

l1 TYPE i,

l2 TYPE C,

l3 TYPE string,

l4(2) TYPE c VALUE ' ' .

l1 = strlen( p_string ).

DO l1 TIMES.

l1 = l1 - 1.

l2 = p_string+l1(1).

if l2 ca 'QWERTYUIOPLKJHGFDSAZXCVBNM0987654321 '.

CONCATENATE l2 l3 INTO l3.

else.

REPLACE l2 WITH l4 INTO l2.

CONCATENATE l2 l3 INTO l3 SEPARATED BY space.

ENDIF.

ENDDO.

WRITE: l3.

Read only

Faaiez
Product and Topic Expert
Product and Topic Expert
0 Likes
5,382

Hi

You can use the following code as an example:

data l_string type string VALUE `## The replacement ## was sucessful !!!`.

replace ALL OCCURRENCES OF REGEX '(##)' in l_string with ''.
CONDENSE l_string.

Please read the following article for further detail on Regular expressions:

[Regex Toy- Testing Regular Expressions In ABAP|http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/1f9cd701-0b01-0010-87b8-f86f9b7b823f]

Regards

Read only

Former Member
0 Likes
5,382

Hi Faaiez Sallie ,

Thanks for your reply.

it is working fine when i write a test program.

but when i am using the same in my code it is not wotking.

please see my code below.

loop at lt_content1 into ls_content1.

w_string = ls_content1-line.

replace ALL OCCURRENCES OF REGEX '(##)' in w_string with ' '.

*CONDENSE w_string.

ls_content1-line = w_string.

*modify lt_content from ls_content1.

endloop.

i am surprised. please let me know what could be the reason.

regards,

Kishan

Read only

Former Member
0 Likes
5,382

Right, it's time to ask a really silly and basic question. How do you know that hash characters exist in the string?. In previous posts it's already been pointed out that unprintable characters like line-feed and carriage returns will show as Hash characters when displayed/printed.

You can't use REPLACE all occurances of '##' unless there physically are hash characters in the string, which by all accounts sounds like there are not.

If is a carriage-return/line-feed in the string you can remove it like this, as alrwady pointed out:

DATA: v_crlf(2) type X value '0D0A'.

REPLACE ALL OCCURRENCES OF v_crlf IN str WITH SPACE.

Jason

Read only

Former Member
0 Likes
5,382

use replace keyword in loop statement . definitly it will work as per your requirement

Read only

andreas_mann3
Active Contributor
0 Likes
5,382

or simply use fm PREPARE_STRING

A.

Read only

0 Likes
5,382

Hi all,

i am bale to get the text without ## symbol in test program.

w_string = ' ##He completed successful delivery of ##NanoTime cons. ##He did '.

split w_string at '.' into w_string1 w_string2.

CALL FUNCTION 'SSM_REPLACE_CHAR_BY_SPACE'

EXPORTING

INPUT_STRING = w_string1

CHAR = '#'

IMPORTING

OUTPUT_STRING = w_string1 .

CALL FUNCTION 'SSM_REPLACE_CHAR_BY_SPACE'

EXPORTING

INPUT_STRING = w_string2

CHAR = '#'

IMPORTING

OUTPUT_STRING = w_string2.

write : w_string1.

write : w_string2.

but when i use same code in my development it is not working.

my origibnal code is as below:

split ls_instr3 at '. ' into w_str1 w_str2 w_str3 w_str4. +++> here ls_instr3 is with text from FM output.

CALL FUNCTION 'SSM_REPLACE_CHAR_BY_SPACE'

EXPORTING

INPUT_STRING = w_str2

CHAR = '#'

IMPORTING

OUTPUT_STRING = w_str2.

but in debugging mode when i change the text with copy paste. I mean just copying the same text from w_str2 and pasting in debugging mode.

then it working.

I am not getting why this not working. as per my observation, when we hardcode the text it is working. when getting the text from FM and passing it to CALL FUNCTION 'SSM_REPLACE_CHAR_BY_SPACE' it is not working.

how to solve the above issue.

even below one :::--->

data l_string type string VALUE `## The replacement ## was sucessful !!!`.

replace ALL OCCURRENCES OF REGEX '(##)' in l_string with ''.

CONDENSE l_string.

write : l_string.

having the same problem. In test program it is working. in my original development it is not working.

REgards,

Kishan

Read only

0 Likes
5,382

Hi Kishan,

Iam not sure if you already tried with the class attributes.

Check this once:


DATA:c_tab VALUE cl_abap_char_utilities=>HORIZONTAL_TAB,
      text1 TYPE string.

REPLACE ALL OCCURRENCES OF c_tab IN text1 WITH space.

if it is not working check with new line attribute as well.


DATA: c_new value cl_abap_char_utilities=>newline,
      text1 TYPE string.
REPLACE ALL OCCURRENCES OF c_new IN text1 WITH space.

Regards,

Swarna Munukoti

Read only

0 Likes
5,382

Hi Swarna,

Thanks for your reply.

I already tried with the same . No use..

REgards,

Kishan

Read only

0 Likes
5,382

Its done....

Thanks to all.

Regards,

Kishan

Read only

0 Likes
5,382

Last post 16-sept. Post before that: 2-feb.

It took you that long to solve it? I do hope you didn't remove the characters manually...

Read only

0 Likes
5,382

Hi all

REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>CR_LF in Text WITH space.

Try this one......works well

Thank you.

Guruprasad.G

Read only

0 Likes
5,382

Thats right. Thanks a lot, it really works.

Read only

Former Member
0 Likes
5,382

Hi,

find the test code below.

DATA: hex1(1) TYPE x VALUE 'A0'.

DATA: hex2(1) TYPE x VALUE '20'.

DATA: uhex1(2) TYPE x VALUE '00A0'.

DATA: uhex2(2) TYPE x VALUE '0020'.

DATA: char1(1) TYPE c.

DATA: test_string TYPE string VALUE 'Stuff in here'.

DATA: test_xstring TYPE xstring.

****Convert the Character String to Binary String

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = test_string

IMPORTING

buffer = test_xstring.

IF cl_abap_char_utilities=>charsize = 1.

REPLACE ALL OCCURENCES OF hex1 IN test_xstring WITH hex2 IN BYTE MODE.

ELSE.

REPLACE ALL OCCURENCES OF uhex1 IN test_xstring WITH uhex2 IN BYTE MODE.

ENDIF.

CLEAR test_string.

DATA:

convin TYPE REF TO cl_abap_conv_in_ce.

CALL METHOD cl_abap_conv_in_ce=>create

EXPORTING

input = test_xstring

RECEIVING

conv = convin.

CALL METHOD convin->read

IMPORTING

data = test_string.

WRITE: / test_string.