Get data between a string?

Posted on 2006-05-10
Last Modified: 2010-04-23
How do I get data between a string?

"************<hello world>***************************"

how do i return hello world without the < and > ?

the easiest .net efficient way

the **** is symbolizing a random length.
Question by:Hepen
    LVL 9

    Accepted Solution

    this is one way to get the the string

    Dim sTmpVal As String = "****************<fundoo world>**************"

    MessageBox.Show(sTmpVal.Substring(sTmpVal.LastIndexOf("<") + 1, (sTmpVal.LastIndexOf(">") - sTmpVal.LastIndexOf("<")) - 1))

    the basic idea is to extract the values from the string and to get that we need to find the starting point and ending point
    LVL 17

    Expert Comment

    Always the sucker for a RegEx, you can try this too:

    Dim regx As New System.Text.RegularExpressions.Regex("^.*[<]{1}(?<TheString>([\w\s]{0,}))[>]{1}.*$")
    Dim str As String = "************<hello to 24 the world>***************************"

    With regx.Match(str)
         MsgBox(regx.Replace(str, .Groups("TheString").Value))
    End With
    LVL 96

    Expert Comment

    by:Bob Learned
    Easier Regex pattern:

      Dim pattern As String = "[\w\s]+"

      Dim match As New Regex(input, pattern)
      If match.Success Then
      End If

    LVL 12

    Expert Comment

    Hello, Hepen,

    If you are sure that you have a "<" and at least one character prior to it, you could use:

            strTest.Split("<"c, ">"c)(1)

    where strTest contains your string.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now