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: 

Reg: Replacement of second occurance of character in string

Former Member
0 Kudos

Hi,

Consider one string1 = 'ABCDAE' OR string2 = 'SHEETAL'.

I want to replace the second occurance of A in above string1.and second occurance of E in above string2 with any differnt character.

I tried with offset calculation , length , replace , split stmts.

but always first occurance is getting replace.

Please provide your ideas.

Regards,

Shital

2 REPLIES 2

Former Member
0 Kudos

try regular expressions

REPLACE REGEX

Former Member
0 Kudos

Hi,

Try this.

data: string1 type char10 value 'ABCDAE',
        len     type i.

  write: / string1.
  search string1 for 'A'.

  if sy-subrc = 0.
    add 1 to sy-fdpos.
    len = strlen( string1 ) - sy-fdpos.
    replace 'A' in string1+sy-fdpos(len) with '!'.
    write: / string1.
  endif.

Darren