Results 1 to 6 of 6

Thread: Regex match conversion

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    6

    Regex match conversion

    I am trying to change the string I get from a Regex match. I keep getting an invalid cast from a Match object to a string. I am fairly new to this so any help is appreciated.
    Code:
    rghfinMatch = (rghfinRegex.Match(strTool))
    rghfinStrip = Microsoft.VisualBasic.Left(CStr(rghfinMatch), 1)
    Thanks in adavnce,
    Wil

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. rghfinMatch = (rghfinRegex.Match(strTool))
    2. rghfinStrip = Microsoft.VisualBasic.Left(CStr(rghfinMatch[b].Value[/b]), 1)

    I don't know what else you attempting to do with it, so I didn't change any other code except that in bold.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    6
    Thank you that is exactly what I was missing.

    Wil

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I would also replace the second line, with more .Net standard functions...
    VB Code:
    1. Dim rghfinStrip As String = rghfinMatch.Value.Chars(0)

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    6
    The last piece of code would work if in the cases I only need the a single Char. I have other times I will need parts of the matches that have to be determined at run time. Is there any other way of wrting this code.
    Code:
                sineMatch = CStr((sineRegex.Match(strTool).Value))
                sineStrip = Microsoft.VisualBasic.Left(sineMatch, (sineMatch.Length - 4))
    The project I am wrting is to evaluate string and create formated names from them with only certain parts being used in the final name.

    Wil

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. sineStrip = sineMatch.Value.SubString(0, sineMatch.Length - 4)

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