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: 

REPLACE : want to replace the string

Former Member
0 Kudos

Hello All,

I need to replace a word(GO) in a sentence with another word(GONE). these words are stores in the variables var1(6) & var2(6) used the keyword REPLACE for this But I am getting some unwanted blank spaces. I used CONDENE keyword then also one blank space remains. I should not get any unwanted blank space. Please help me.

Data : var1(6) type c.

Data : var2(6) type c.

Data : var3(15) type c.

Data : len type i.

var1 = 'GO'.

var2 = 'GONE'.

var3 = 'ABCDGOEFGH'

len = strlen(var1).

REPLACE var1LENGTH len WITH var2 INTO var3.

Then the new sentence is coming like

ABCDGONE EFGH

I used CONDENSE then again it is coming like.

ABCDGONE EFGH

I need the sentence like ABCDGONEEFGH

Regards,

Lijo John

1 ACCEPTED SOLUTION

JozsefSzikszai
Active Contributor
0 Kudos

hi,

you have to use CONDENSE var3 NO-GAPS . (CONDENSE alone will reduce only to one space.)

hope this helps

ec

10 REPLIES 10

milusai
Participant
0 Kudos

REPLACE ALL OCCURRENCES OF 'GO' in var3 WITH 'GONE'.

JozsefSzikszai
Active Contributor
0 Kudos

hi,

you have to use CONDENSE var3 NO-GAPS . (CONDENSE alone will reduce only to one space.)

hope this helps

ec

Former Member
0 Kudos

HI,

Plz try and Check the Code.

Condense (VAr1).

Condense(VAr2).

Replace Var1 withe Var2 into Var 3.

Regards

Sumit Agarwal

Former Member
0 Kudos

hi,

check the data type length of variables..than it is coming right..

Data : var1(2) type c.

Data : var2(4) type c.

Data : var3(12) type c.

Data : len type i.

Regards,

Deepthi.

Former Member
0 Kudos

Hello

Declare

Data : var2(4) type c.

0 Kudos

Dear Friends,

I cannot restrict the variable length. The data length will be keep changing as per the situation.

eg.

va1 = 'Please raise the Travel Req'

var2 ='Please raise an Emergency Travel Req'

and some space should be there. I dont want to chage that spaces also.

Regards,

Lijo

0 Kudos

Data : var1(3) type c.
Data : var2(12) type c.
Data : var3(40) type c.
Data : len type i.

var1 = 'the'.
var2 = 'an Emergency'.
var3 = 'Please raise the Travel Req'.
len = strlen( var1 ).
REPLACE var1 LENGTH len WITH var2 INTO var3.

Former Member
0 Kudos

Hi,

I have changed the code written by you.

Check this-

Data : var1(6) type c.
Data : var2(6) type c.
Data : var3(15) type c.
Data : len type i.


var1 = 'GO'.
var2 = 'GONE'.

var3 = 'ABCDGOEFGH'.

len = strlen( var1 ).

REPLACE var1 LENGTH len WITH var2 INTO var3.

condense var3 no-gaps.
write:var3.

Former Member
0 Kudos

Hi,

Plz check your variable declaration part :


Data : var1(2) type c.
Data : var2(4) type c.
Data : var3(12) type c.
Data : len type i.

or

Use

" CONDENSE  var3 No-GAPS. "

thanx.

Former Member
0 Kudos

Hi,

Try this:

Data : var1(6) type c.

Data : var2(6) type c.

Data : var3(15) type c.

Data : len type i.

var1 = 'GO'.

var2 = 'GONE'.

var3 = 'ABCDGOEFGH'.

len = strlen( var1 ).

REPLACE var1 LENGTH len WITH var2 INTO var3.

condense var3 no-gaps.

write var3.

Regards,

Surinder