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: 

reading each character of a string

Former Member
0 Kudos

hi all,

my requirement is :

i have a string 'NAKUL,AGARWAL'.

i want to read each alphabet of this string and then check if ',' comes ,i have to do certain coding and change it to '.'.

can you help me?

9 REPLIES 9

Former Member
0 Kudos
data : v_name(15) value 'NAKUL,AGARWAL'.

search v_name for ','.
if sy-subrc eq 0.
  replace ',' with '.' into v_name.
endif.

raymond_giuseppi
Active Contributor
0 Kudos

Perhaps you could try any of these

REPLACE ',' WITH '.' INTO string.

SPLIT string at ',' INTO string1 string2.

regards

Former Member
0 Kudos

Use REPLACE

REPLACE f ...WITH g

...INTO h.

Former Member
0 Kudos

you can use search and replace .

else

data : len type i,

v_chr ,

pos type i.

compute len = strlen( str1 ).

do len times.

v_chr = str1+pos(1).

if v_chr = ','.

<do coding>

endif.

pos = pos + 1.

enddo.

regards

shiba dutta

0 Kudos

refer demo code

Character occurance in a String -

PARAMETERS : P_CHAR TYPE C LOWER CASE.

data str type string.

dATA: LEN TYPE I,

COUNT TYPE I,

PASS TYPE I VALUE '0'.

str = 'amita'.

CONDENSE STR.

LEN = STRLEN( STR ).

DO LEN TIMES.

IF P_CHAR = STR+pass(1).

COUNT = COUNT + 1.

ENDIF.

pass = pass + 1.

ENDDO.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

v1 = 'NAKUL,AGARWAL'.

Replace all occurrences of ',' with '.' in v1.

Former Member
0 Kudos

Hi Nakul,

Check the code for u r requirement,

REPORT ZEX31 .

PARAMETER : str1(20) .

DATA : v2(20),

d TYPE i,

e TYPE i,

f TYPE i.

d = 0.

e = 0.

f = strlen( str1 ).

WHILE d NE f.

IF str1+d(1) ne ','.

v2e(1) = str1d(1).

d = d + 1.

e = e + 1.

ELSE.

v2+e(1) = '.'.

e = e + 1.

d = d + 1.

ENDIF.

ENDWHILE.

write : / str1.

write : / v2.

Former Member
0 Kudos

thanks a lot guys for the answers

Former Member
0 Kudos

Hi,

use this statement,

replace all occurences of ',' with '.' in v_string.

Regards,

Aman