• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

Get data between a string?

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.
0
Hepen
Asked:
Hepen
1 Solution
 
Naveen SwamyCommented:
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
0
 
ZeonFlashCommented:
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
0
 
Bob LearnedCommented:
Easier Regex pattern:

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

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

Bob
0
 
omegaomegaDeveloperCommented:
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.

Cheers,
Randy
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now