-
Mar 6th, 2018, 08:30 PM
#1
Thread Starter
Addicted Member
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
-
Mar 6th, 2018, 08:42 PM
#2
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("[", "")
-
Mar 6th, 2018, 10:39 PM
#3
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
-
Mar 7th, 2018, 03:59 AM
#4
Thread Starter
Addicted Member
Re: unterminated[] while parsing string
it worked fine as soon as i added "\" before the special regex char
-
Mar 7th, 2018, 08:08 AM
#5
Re: unterminated[] while parsing string
Originally Posted by techgnome
"" 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|