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 and Condense

Former Member
0 Likes
3,112

Hi ,

I have a string in this way .

<b>' Welcome # to## ABA#P '</b>

I would like to remove the occurances of # so that the string output will be

<b>' Welcome to ABAP '</b>

if i use the replace and the condense statements, the output is wrong and the data im getting is incorrect and is in the following was ' WelcometoABAP '

Any solution to this ???

Regards

Mustameer

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,988

Hello,

Just copy paste the code....


data: str type string.

str = 'Welcome # to## ABA#P'.

replace all occurrences of substring '#' in str with ' '.

write: str. " String with gaps..."

condense str.

write: str.

Hope it helps.

Regards,

Maheswaran.B

12 REPLIES 12
Read only

Former Member
0 Likes
1,988

Hi Mustameer

yes condense will remove leading and closing blanks are completely removed and any other directly consecutive blanks are all replaced by exactly one space character or - if NO-GAPS is specified - are also removed completely.

regards

kishore

Read only

0 Likes
1,988

Use REPLACE ALL OCCURRENCES OF '#' WITH SPACE.

regards,

Suresh Datti

Read only

Former Member
0 Likes
1,988

DATA: A(4) TYPE C,A1(20) VALUE 'Welcome # to## ABA#P'.

REPLACE ALL OCCURRENCES OF '#' IN a1 with space.

write a1.

its working

<b>reward if useful</b>

Read only

0 Likes
1,988

The ourput that i get when i use the all occurances option is 'Welcome to ABA P ' as the # will be replaced by a ' ' .

but i want to know how do i remove this space while maintaining the space b/w the words .

Read only

0 Likes
1,988

You have to split the string into two diff strings & use CONDENSE on the string that holds 'ABA P'; And the concatenate the two strings separated by space.

Suresh Datti

Read only

0 Likes
1,988

HI khan

then you have concatenate

field = 'welcome to aba p'.

concatenate field0(14) field15(1) into field.

regards

kishore

Read only

0 Likes
1,988

hi,

DATA: A(4) TYPE C,

A1(20) VALUE 'Wel#ome # to## A#A#P '.

REPLACE ALL OCCURRENCES OF '#' IN a1 with space.

write a1.

O/p which i got : Welome to AAP.

i had tried the code and it is wrking fine , infact it will take care of the space by itself.

Cheers

Sunny

Read only

0 Likes
1,988

its working fine for me too...just copy my code and try in ur system...

<b>reward if useful</b>

Read only

0 Likes
1,988

Thank you everybody,

Issue resolved.

Appropriate points alloted

Read only

Former Member
0 Likes
1,988

Hi,

try this....

string = ' Welcome # to## ABA#P ' 
REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB IN string WITH SPACE

write: string.

Regards

vijay

Read only

Former Member
0 Likes
1,989

Hello,

Just copy paste the code....


data: str type string.

str = 'Welcome # to## ABA#P'.

replace all occurrences of substring '#' in str with ' '.

write: str. " String with gaps..."

condense str.

write: str.

Hope it helps.

Regards,

Maheswaran.B

Read only

Former Member
0 Likes
1,988

Without your string manipulation you can do the following way.

Your string ' Welcome # to## ABA#P '

Replace # value with null value, usually with this '' (single quotes) not with the space.

I think this should resove your issue.