Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6657637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:47:36+00:00 2026-05-26T01:47:36+00:00

I am trying to find a string inbetween two other strings. This function is

  • 0

I am trying to find a string inbetween two other strings. This function is working fine but as soon as I use escaped characters (“”) it stops working and a runtime error occurs. Function & working / non-working examples below:

Function:

Public Function GetBetween(ByVal haystack As String, ByVal needle As String, ByVal needle_two As String) As String
    Dim istart As Integer = InStr(haystack, needle)
    If istart > 0 Then
        Dim istop As Integer = InStr(istart, haystack, needle_two)
        If istop > 0 Then
            Dim value As String = haystack.Substring(istart + Len(needle) - 1, istop - istart - Len(needle))
            Return value
        End If
    End If
    Return Nothing
End Function

Example working:

Dim Haystack As String = "hello find me world"
    Dim FindIt As String = GetBetween(Haystack, "hello", "world")
    MessageBox.Show(FindIt)

Example non-working (Using escaped “”” Chars):

Dim Haystack As String = "<input type=""hidden"" name=""testsubmit"" id=""testsubmit"" value=""findme""  />"
    Dim FindIt As String = GetBetween(Haystack, "id=""testsubmit"" value=""", """")
    MessageBox.Show(FindIt)

Error:
ArgumentOutOfRangeException was unhandled
Length cannot be less than zero.
Parameter name: length

So basically my function is not allowing me to use it when searching for escaped chars.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:47:37+00:00Added an answer on May 26, 2026 at 1:47 am

    You can easily determine that the problem has nothing to do with escaped quotes by replacing them in your string with some other character and seeing that the function call fails in exactly the same way.

    The real difference between your two test strings is that in your first example, your needle_two string does not appear in your needle string, while in your second example it does. In other words, your problem is that you start looking for needle_two where needle begins rather than where it ends, and istop ends up inside of needle.

    What you need to do is start searching after needle stops:

    Dim istop As Integer = InStr(istart + Len(needle), haystack, needle_two)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to find out if a string value EndsWith another string. This 'other
I'm trying to find all permutations of a string and sort them alphabetically. This
I'm trying to find a Delphi function that will split an input string into
I'm trying to find LONG UserAgent strings with LogParser.exe in my IIS logs. This
I am learning regular expressions and I am trying find this string day1otlk_XXXX.gif where
I've been trying to find a string in PHP that matches something like this:
I am trying to find some text RegEx /\w*http:[/][/]bit.ly[/]\w*/ig that will find this string
I've been trying to use Here-documents , but it's not working. What might be
Im trying to use the string::find method to determine if the string hello (with
I'm trying to find a date-string format that will allow me to use Date.parse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.