Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the characters between 2 other characters?

Tags:

string

vb.net

I have a string which at some point contains the set of characters in the following format [123].

What I would like to do is get the characters between [] but the characters in between are never the same length.

How would I go about this in VB.NET?

like image 825
LiamGu Avatar asked Feb 10 '11 10:02

LiamGu


People also ask

How do I find the text between two characters?

To extract part string between two different characters, you can do as this: Select a cell which you will place the result, type this formula =MID(LEFT(A1,FIND(">",A1)-1),FIND("<",A1)+1,LEN(A1)), and press Enter key. Note: A1 is the text cell, > and < are the two characters you want to extract string between.

How do I extract text between characters in Excel?

Extracting text between characters in Excel 365 In Excel 365, you can get text between characters more easily by using the TEXTBEFORE and TEXTAFTER functions together. This formula also works nicely for extracting text between two occurrences of the same character.

How do I get text between brackets in Excel?

To extract the text between any characters, use a formula with the MID and FIND functions. The FIND Function locates the parenthesis and the MID Function returns the characters in between them.


2 Answers

Dim s As String = "foo [123]=ro bar"
Dim i As Integer = s.IndexOf("[")
Dim f As String = s.Substring(i + 1, s.IndexOf("]", i + 1) - i - 1)
like image 139
LukeH Avatar answered Oct 27 '22 05:10

LukeH


Dim s As String = "nav[1]=root"
dim result as String = s.Substring(s.IndexOf("[") + 1, s.IndexOf("]", s.IndexOf("[")) - s.IndexOf("[") - 1)
like image 42
Davide Avatar answered Oct 27 '22 06:10

Davide