Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    61

    Unanswered: replace a substring in a string by another substring

    Hi All,

    I want to replace a substring in a string by another substring.
    Ex:

    replace('abcdef', 'cd', 'xx') --> 'abxxef'

    How can I do?

    Thanks in advanced,
    Thi Nguyen

  2. #2
    Join Date
    Aug 2004
    Posts
    42
    stuff (string, start_position, length, replacement_string) is close to what you want.

  3. #3
    Join Date
    Jul 2004
    Posts
    61
    Thanks a lot.
    I didn't tell you that I'm using Anywhere 5.0.
    I try to do that but Anywhere 5.0 not support "stuff" function.
    Could you tell me more?

    Regards,
    Thi Nguyen

  4. #4
    Join Date
    Aug 2004
    Posts
    42
    Don't know anything about Anywhere so following may still not work, but anyway...

    In the language of the C preprocessor you could define STUFF() as:

    #define STUFF(A,B,C,D) substring (A, 1, B - 1) \
    + D \
    + substring (A, B + C, case \
    when char_length (A) - B - C + 1 < 0 \
    then 0 \
    else \
    char_length (A) - B - C + 1 \
    end)

    So, cleaned up that's:

    substring (A, 1, B - 1)
    + D
    + substring (A, B + C, case
    when char_length (A) - B - C + 1 < 0 \
    then 0
    else
    char_length (A) - B - C + 1
    end)

    All that case...end stuff is to prevent a negative number being passed to substring.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •