Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2006
    Posts
    157

    Unanswered: Needs help in string

    Hi: Can any one please tell me how to i change 00032 value in the string without disturbing the original size of the string?

    the second curly bracket upto the starting character "O"is always same in the string

    20070302 HD000000000{000000000{00032ODSS HCS1

    newvalue=65
    so it will be
    20070302 HD000000000{000000000{00065ODSS HCS1

    Thanks.

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    I would use InstrRev to find the LAST occurrance of "{", and InstrRev again to find the last position of the "O" character.

    Now, given these two positions, you can use the MID SUB (as opposed to the MID FUNCTION) to replace the first string's substring value with the replacement string.

    the following should be close.
    Code:
    MID(YourString, InstrRev(YourString, "{")+1, (INSTRREV(YourString, "O"))-( InstrRev(YourString, "{")+1))="00065"
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    Dim TempStr As String
    Dim OriginalStr As String
    Dim NewStr As String
    
    OriginalStr = "20070302 HD000000000{000000000{00032ODSS HCS1"
    TempStr = RIGHT(OriginalStr, 15)
     'TempStr now contains "{00032ODSS HCS1"
    TempStr = Replace(TempStr, "00032", "00065")
     'TempStr now contains "{00065ODSS HCS1"
    NewStr = Left(OriginalStr, (Len(OriginalStr) - 15)
     'NewStr now contains "20070302 HD000000000{000000000"
    NewStr = NewStr & TempStr
     'NewStr now contains "20070302 HD000000000{000000000{00065ODSS HCS1"
    I find this method simpler to understand...
    Feel free to ask any questions
    George
    Home | Blog

  4. #4
    Join Date
    Jul 2006
    Posts
    157
    Thanks man. This is a really very good site

Posting Permissions

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