Skip to Content

Replacing characters in a string

Hi,

with a character variable you can manipulte the contents via

var+5(02) = 'XY'.

With a string variable this is not allowed. Is there any other way of doing this except copying the string to a char variable, doing the change and copy it back? Another way of doing this concatenating the first part, the new chars and the rest together, but this is an ugly solution too....

Why is it syntactically ok to read parts of a string, but not to write? Is it because a string content is shared between several variables all pointing to the same string content?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 21, 2007 at 07:02 AM

    try this.

    REPLACE SECTION [OFFSET off] [LENGTH len] OF text WITH new.

    Awrd Points if Useful

    bhupal

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 21, 2007 at 07:02 AM

    use REPLACE ...

    e.g.

    DATA field(10) TYPE C.

    MOVE 'ABCB' TO field.

    REPLACE 'B' WITH 'string' INTO field.

    OR

    DATA: pattern(6) TYPE C VALUE 'ABC',

    len TYPE I,

    repl_string(6) TYPE C VALUE '123456',

    field(12) TYPE C VALUE 'abcdeABCDE'.

    REPLACE pattern WITH repl_string INTO field.

    Edited by: Sharayu Kumatkar on Dec 21, 2007 12:32 PM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 21, 2007 at 07:03 AM

    Hi,

    This can be done using REPLACE command.

    Regards,

    Lalit

    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.