Results 1 to 3 of 3

Thread: Simple Find and Replace

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Location
    London, England
    Posts
    213

    Simple Find and Replace

    I want to do a simple find and replace but I cannot get this to work with variables using the Replace() Function:

    sLine = "Wednesday 15/08/01"
    sOldDate = Trim(Mid(sLine, 11, 8))
    sNewDate = Date
    sLine = Replace(sLine, sOldDate, sNewDate)

    Can someone show me how I can get this to work ?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Try this:

    Private Function ReplaceAll(SourceString As String, ReplaceThis As String, WithThis As String)
    Dim Temp As Variant
    Temp = Split(SourceString, ReplaceThis)
    ReplaceAll = Join(Temp, WithThis)
    End Function

    'To call: ReplaceAll(txtSomeTextBox.Text, "OldString", "NewString")

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    I think this is what you're getting at:
    VB Code:
    1. Dim sLine As String
    2. Dim sOldDate As String
    3. Dim sNewDate As String
    4.  
    5. sLine = "Wednesday 15/08/01"
    6. sOldDate = Trim(Mid(sLine, 1, Len(sLine)))
    7. sNewDate = CStr(Format(Date, "dddd dd/mm/yy"))
    8. sLine = Replace(sLine, sOldDate, sNewDate)
    9.  
    10. MsgBox sLine

Posting Permissions

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



Click Here to Expand Forum to Full Width