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

spaces in string

Former Member
0 Likes
698

Dear Gurus,

I have a string .

'My name is Roshan Lilaram Wadhwani'

I need to find the number of spaces used in this string.

Rather i need to segregate the string in two parts after a particular number of spaces.

Regards,

Roshan Lilaram.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
665

TRY THIS


DATA : TEXT(50)  VALUE 'My name is Roshan Lilaram Wadhwani',
       LEN TYPE I,
       POS TYPE I,
       COUNTER TYPE I,
       V_CH,
       V_SPACE VALUE ' ',
       V_TXT(30),
       V_TXT2(20).

COMPUTE LEN = STRLEN( TEXT ).

DO LEN TIMES.
 V_CH = TEXT+POS(1).
 IF V_CH EQ SPACE.
  COUNTER = COUNTER + 1.
 ENDIF.

 IF COUNTER LT 3.
  CONCATENATE V_TXT V_CH INTO V_TXT.
 ELSE.
  CONCATENATE V_TXT2 V_CH INTO V_TXT2.
 ENDIF.
 POS = POS + 1.
ENDDO.

WRITE : / V_TXT.
WRITE : / V_TXT2.

REGARDS

SHIBA DUTTA

5 REPLIES 5
Read only

dev_parbutteea
Active Contributor
0 Likes
665

Hi,

try the folowing codes:

data :

varxx type string value 'Test',

len type i.

len = strlen( varxx ).

write: varxx, ' Lenght:', len.

len2 = len/2.

segregate the string in two parts like this:

move varxx(len2 ) to temp1.

move varxx+len2 to temp2.

Read only

0 Likes
665

Please reward if this solves your problem,

Regards,

Sooness.

Read only

Former Member
0 Likes
665

hi

You can use the function module SWA_STRINGLENGTH_GET to find the number of spaces in the string.

for this you can call this function module twice.

first when you are not going to set the parameter CONDENSE_NO_GAPS.

and get the length of the string with spaces.

after that call the function module againg and set CONDENSE_NO_GAPS = X.

now the length of the string will be without spaces.

you can substract the two to get the number of spaces.

Reward if helpful.

Mohit

Read only

Former Member
0 Likes
666

TRY THIS


DATA : TEXT(50)  VALUE 'My name is Roshan Lilaram Wadhwani',
       LEN TYPE I,
       POS TYPE I,
       COUNTER TYPE I,
       V_CH,
       V_SPACE VALUE ' ',
       V_TXT(30),
       V_TXT2(20).

COMPUTE LEN = STRLEN( TEXT ).

DO LEN TIMES.
 V_CH = TEXT+POS(1).
 IF V_CH EQ SPACE.
  COUNTER = COUNTER + 1.
 ENDIF.

 IF COUNTER LT 3.
  CONCATENATE V_TXT V_CH INTO V_TXT.
 ELSE.
  CONCATENATE V_TXT2 V_CH INTO V_TXT2.
 ENDIF.
 POS = POS + 1.
ENDDO.

WRITE : / V_TXT.
WRITE : / V_TXT2.

REGARDS

SHIBA DUTTA

Read only

Former Member
0 Likes
665

i have used split command.

Thank you all very much.