Results 1 to 5 of 5

Thread: unterminated[] while parsing string

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2017
    Posts
    147

    unterminated[] while parsing string

    Code:
    HOVResponse = Replace(HOVResponse, "[", string.empty)
    i am sure this is a simple problem to solve but it has me stumped, i understand [ is a special regex character but how do i get around this and replace [ from a string as it is throwing the exception in the title

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: unterminated[] while parsing string

    Apologies if I'm missing something more complex about your needs. I don't have access to VB.Net at the moment to test this, but I would think something like the following would work, presuming that you want to simply strip out all "[" characters from a string:

    Code:
    HOVResponse = HOVResponse.Replace("[", "")

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: unterminated[] while parsing string

    "" and String.Empty are really the same thing, so either should work. But I would use the HOVResponse.Replace. Not sure why Replace would give you an error like that, RegEx doesn't have anything to do with it as far as I know. Unless it's doing something with it on the backend, or if it's a custom Replace function. To answer your question directly though, if you are using RegEx to do a replace, and want to use a RegEx character, you need to escape it ... I think with the \

    Code:
    HOVResponse = Replace(HOVResponse, "\[", string.empty)
    But that doesn't feel right either.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2017
    Posts
    147

    Re: unterminated[] while parsing string

    it worked fine as soon as i added "\" before the special regex char

  5. #5
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: unterminated[] while parsing string

    Quote Originally Posted by techgnome View Post
    "" and String.Empty are really the same thing, so either should work. But I would use the HOVResponse.Replace. Not sure why Replace would give you an error like that, RegEx doesn't have anything to do with it as far as I know. Unless it's doing something with it on the backend, or if it's a custom Replace function. To answer your question directly though, if you are using RegEx to do a replace, and want to use a RegEx character, you need to escape it ... I think with the \

    Code:
    HOVResponse = Replace(HOVResponse, "\[", string.empty)
    But that doesn't feel right either.

    -tg
    As far as I can tell, if we're in a VBA context, Replace() is a built-in function and may use regex by default? I don't think OP understood your point that in general, VB .NET developers don't use and have no clue what a built-in function does.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

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