Skip to Content
author's profile photo Former Member
Former Member

reading each character of a string

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?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2007 at 07:50 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

  • author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2007 at 07:41 AM
    data : v_name(15) value 'NAKUL,AGARWAL'.
    
    search v_name for ','.
    if sy-subrc eq 0.
      replace ',' with '.' into v_name.
    endif.
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 11, 2007 at 07:42 AM

    Perhaps you could try any of these

    REPLACE ',' WITH '.' INTO string.

    SPLIT string at ',' INTO string1 string2.

    regards

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2007 at 07:45 AM

    Use REPLACE

    REPLACE f ...WITH g

    ...INTO h.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 11, 2007 at 07:51 AM

    Hi,

    v1 = 'NAKUL,AGARWAL'.

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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2007 at 07:56 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2007 at 08:51 AM

    thanks a lot guys for the answers

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2007 at 11:07 AM

    Hi,

    use this statement,

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

    Regards,

    Aman

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.