Application Development 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: 

String Manipulation with blank space at the end

Former Member
0 Kudos

Hi All,

DATA: str1(999),

a(10),

b(10).

DATA: len TYPE i.

a = 'Welcome'.

b = 'To all'.

CONCATENATE a b INTO str1 RESPECTING BLANKS.

len = STRLEN( str1 ).

WRITE: len.

result : 16.

If I declared str1 as string result is 20. Because in above case empty space is truncated at last .

So any otherway to getting result 20 with out declaring str1 as string.

7 REPLIES 7

former_member156446
Active Contributor
0 Kudos

before concatenating fill the blanks space of a and b with some character say _ and concatenate and find the string length.

after concatenating replace all occurance of '_ ' in string1 with ' '.

Former Member
0 Kudos

Dear Vinoth

Try as follows


DATA: BEGIN OF sentence,
        word1(30) TYPE c VALUE 'She',
        word2(30) TYPE c VALUE 'feeds',
        word3(30) TYPE c VALUE 'you',
        word4(30) TYPE c VALUE 'tea',
        word5(30) TYPE c VALUE 'and',
        word6(30) TYPE c VALUE 'oranges',
      END OF sentence,
      text TYPE string.

text = sentence.

0 Kudos

dear Nelson,

you are telling with string , but i need it with out string , using only character format str(999) .

Former Member
0 Kudos

what is the problem using string instead.

Regards,

Lalit Mohan Gupta.

Former Member
0 Kudos

Try this out.

DATA: str1(999),
a(10),
b(10).
DATA: len TYPE i,
      wc(2) value ' #'.

a = 'Welcome'.
b = 'To all'.
translate a using wc.
translate b using wc.
concatenate a b into str1.
len = strlen( str1 ) .
replace all occurrences of '#'  in str1 with space .
write : len.

Result : 20.

This will solve the issue

Regards,

Gurpreet

Former Member
0 Kudos

Hi vinoth ,

To get spaces at last ,


data : str1 type char10 , 
         len type i .

str1 = 'the ' .                  " space given by pressing space bar button
len = STRLEN( str1 ).     " in len we get it as 3 , coz 'the ' is 3 only .
**************
str1 = 'the ' .                 " space given by pressing ALT 2 5 5 
len = STRLEN( str1 ).   " in len we get it as 4 , coz 'the ' is 3 and 1 space is given by pressing ALT 255 .


This works,

Hope it might be helpfull,

Regards,

Aby

Former Member
0 Kudos

I figured it thanks