Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want go get string between two strings. I will use for url

For example

VB
dim main as string = "kgjhnbkfm glnvfkdşlv http://ghkng.xfg/ngbf.png gvlkdjg"
dim before as string="http://"
dim after as string = ".png"
dim useless as string='I need to get between theese strings (before and after)
dim urlfinal as string=before+useless+after
Posted

Use a Regex:
VB
Dim regex As Regex = New Regex( _
      "(?<=http://).*?(?=\.png)", _
    RegexOptions.Multiline _
    Or RegexOptions.CultureInvariant _
    Or RegexOptions.IgnorePatternWhitespace _
    Or RegexOptions.Compiled _
    )
Dim InputText As String = "kgjhnbkfm glnvfkdşlv http://ghkng.xfg/ngbf.png gvlkdjg"
Dim m As Match = regex.Match(InputText)
If (m.Success) Then
    Console.WriteLine(m.Value)
End If
 
Share this answer
 
You could use rexex for this:
Expresso - A Tool for Building and Testing Regular Expressions[^]
MAtch the part that is preseded by and followed by.
 
Share this answer
 
I would suggest you look at regular expressions[^].

A quick C# solution (maybe not the best as my RegExp is not as good as it should be):

C#
string main = "kgjhnbkfm glnvfkdşlv http://ghkng.xfg/ngbf.png gvlkdjg";
Regex pattern = new Regex("(.*)http://(?<urlfinal>(.*)).png(.*)");

Match match = pattern.Match(main);

string urlFinal = "http://" + match.Groups["urlfinal"].Value + ".png";
</urlfinal>


It should be easily convertible to VB.NET.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900