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: 

How to remove unwanted spaces in a string

Former Member
0 Kudos

Hi all,

Iam taking a txt field txt50 which is containing many unwanted spaces between words in it. and i want to remove all unwanted spaces between words. Please tell me the solution it.

1 ACCEPTED SOLUTION

Former Member

use CONDENSE statement

<b>CONDENSE V_STR NO-GAPS.</b>

10 REPLIES 10

Former Member

use CONDENSE statement

<b>CONDENSE V_STR NO-GAPS.</b>

0 Kudos

Hi ,

This is good but i need one space between any 2 words.

0 Kudos

Hi,

than try without no-gaps like this:

data: txt type string.

*

txt = 'txt with space'.

write: / txt.

*

CONDENSE txt.

*

write: / txt.

Former Member
0 Kudos

Hi,

Use CONDENSE <NO-GAPS>

Reward if useful!

Former Member
0 Kudos

Hi,

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.

<b>Reward points</b>

Regards

Former Member
0 Kudos

Use Replace ' ' in text50 to ''. " Check syntax

or try condense text50.

reward points if helpful

Former Member
0 Kudos

Hi,

try this:

data: txt type string.

*

txt = 't x t w i t h s p a c e'.

write: / txt.

*

CONDENSE txt no-gaps.

*

write: / txt.

Regards, Dieter

Former Member
0 Kudos

Hi Chinna,

CONDENSE <VARIABLE NAME> NO-GAPS

Former Member
0 Kudos

Hi,

The CONDENSE statement deletes redundant spaces from a string:

CONDENSE <c> [NO-GAPS].

This statement removes any leading blanks in the field <c> and replaces other sequences of

blanks by exactly one blank. The result is a left-justified sequence of words, each separated by

one blank. If the addition NO-GAPS is specified, all blanks are removed.

DATA: STRING(25) VALUE ' one two three four',

LEN TYPE I.

LEN = STRLEN( STRING ).

WRITE: STRING, '!'.

WRITE: / 'Length: ', LEN.

CONDENSE STRING.

LEN = STRLEN( STRING ).

WRITE: STRING, '!'.

WRITE: / 'Length: ', LEN.

CONDENSE STRING NO-GAPS.

LEN = STRLEN( STRING ).

WRITE: STRING, '!'.

WRITE: / 'Length: ', LEN.

Output:

one two three four !

Length: 25

one two three four !

Length: 18

onetwothreefour !

Length: 15

Note that the total length of the field STRING remains unchanged, but that the

deleted blanks appear again on the right.

Regards,

Bhaskar

Former Member
0 Kudos

Hi Dear

unwanted mean what

can you explain with examples.