String Pattern Matching
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: String Pattern Matching

  1. #1
    Join Date
    Jun 2011
    Posts
    2

    String Pattern Matching

    I'm trying to do a simple Replace() on a string that contains dynamic content within (the time output). Example:
    Code:
    Last message received on 6/26 at 10:35 PM
    How can I refer to the time when it's constantly changing?

    Code:
    strTemp = Replace(strTemp, "Last message received on " & (SOME COMPARISON MAGIC GOES HERE), "")
    I looked into the "Like" operator but I don't think a Boolean return value would help me here. Thanks!

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,823

    Re: String Pattern Matching

    Always use [code][/code] tags when posting code.

  3. #3
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,823

    Re: String Pattern Matching

    You could also use the Instr() function to find the position of "Last message received on" and then parse out the required number of characters using Right$() and Left$() or MID$() functions.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Jun 2011
    Posts
    2

    Re: String Pattern Matching

    I solved my problem using this Regular Expression (& late binding, of course ):

    Code:
    'Create our regular expression object which matches the example: 6/26 at 10:35 PM
        Set reLastMsg = CreateObject("VBScript.RegExp")
        With reLastMsg
            .Pattern = "\d{1,2}.\d{1,2}\s\w{2}\s\d{1,2}:\d{2}\s\w{2}"
            .Global = True
            .IgnoreCase = True
        End With

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: String Pattern Matching

    Please mark your thread Resolved

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center