Remove parts of a string in vb.net - vb.net

Im using the FolderBrowserDialog to pick a path.
It will return for ex. this= C:\Mypath1\Mypath2\DOCS
I would like to remove everything but DOCS.
If i use VBA i would use a InStrRev combined with a left. But now in in VB.net and im not sure how to achieve this, im pretty sure there is something better than my old VBA way?
Anyone there that could help, google failed me.

Try this:
IO.Path.GetFileName("C:\Mypath1\Mypath2\DOCS")
Which returns DOCS.

I am not sure what you want to do. But maybe this can help you get the last part of a string
Dim fullPath As String = " C:\Mypath1\Mypath2\DOCS"
Dim Parts As String() = fullPath.Split("\")
Dim lastPart As String = Parts(Parts.Length - 1)

Related

Documentation for new String.Format syntax in VB.NET ( $ before leading quote mark )

I'm used to the String.Format method in VB.NET:
Dim mystring = String.Format("Today is {0:d}", Now)
Recently, however, I stumbled upon something like this, which is refreshingly shorter:
Dim mystring = $"Today is {Now}"
However, I wasn't able to find documentation for this new syntax. I would like to know how to use format masks with it, if possible.
That is called "string interpolation" so you can find information by searching for that term. That said, format specifiers work the same way as for String.Format:
Dim mystring = $"Today is {Now:d}"

VB.NET | Copy FROM Richtextbox1.Text inside is a Text called myemail#gmx.de:mypass123

I want to Copy myemail#gmx.de to Textbox1 and mypass123 to Textbox2 how would i do it, im trying to make an Auto Register Bot and need that sorry for my Bad EnglishV
You can use string.Split to split a string on a character. You can try something like this.
Dim userInfo = "myemail#gmx.de:mypass123"
Dim parts = userInfo.Split(":")
Textbox1.Text=parts.First()
Textbox2.Text=parts.Last()

How to extract URLs from HTML source in vb.net

My question is: I have a program that fetches the whole source code of a specified URL. The source code will be saved in a variable.
Part of the source code looks like this:
"thumbnail_src":"https:\/\/scontent-fra3-1.blablabla.com\/t51.2885-15\/s640x640\/sh0.08\/e35\/1234567_984778981596410_1107218704_n.jpg","is_video":false,
The code is has quite a bunch of those URLs. I want my code to look for the part "thumbnail_src":" as a marker for beginning the extraction process and stop the extraction at ","is_video":
This should be obviously done in a loop until all URLs are being extracted and saved into a listing variable.
How can I achieve that?
I am trying to get that Regexp into my sourcecode. The one that codexer wrote, which is correct but I am getting eerrors in visual basic net.
Dim regex As Regex = New Regex("thumbnail_src""": """(.*)""","""is_video")
Dim match As Match = regex.Match(sourceString)
If match.Success Then
Console.WriteLine(match.Value)
End If
I tried it this way..and also that way:
Dim regex As Regex = New Regex("thumbnail_src":"(.*)","is_video")
Something is wrong the way I am entering the regex code.
Here is the correct one I need to implement:
https://regex101.com/r/hK0xH8/4
thumbnail_src":"(.*)","is_video
In light of your recent edit I am going to redo this answer.
Since it looks like everything is coming in on one line of text here is how I would handle it.
Dim LargetxtLine as String = TheVeryLargylineofText
Dim CommaSplit as String() = LargetxtLine.split(","c)
Dim URLList as New List(of String)
Dim RG as New Regex("\"":\""(.*)\""")
For Each str as String in CommaSplit
If str.contains("thumbnail_src") Then
URLList.Add(RG.Match(str).value)
End If
Next
This will break up the long line of text into managable chunks and then it uses regex to add it to a list of URL's (URLList)
From there you can do just about anything with a list(of String).
There is another way of doing it without splitting on the ,'s
if you use this Regex
"thumbnail_src\"":\""(.*?)\"",\""is_video"
Adding the "?" in there turns it into a greedy statement meaning that it will stop at the first occurance.
After that you could create a URLList like this
DIM RG as New Regex("thumbnail_src\"":\""(.*?)\"",\""is_video")
Dim URLList as MatchCollection = RG.Matches(reallybigString)
It's really personal preference

VB.NET Get the V variable from a youtube url

I am writing a program to play videos from the internet in it.
for the user to get the video they have to paste a url in E.G. https://www.youtube.com/watch?v=5xniR1GN69U that url works but this one https://www.youtube.com/watch?feature=c4-overview&list=UUOYWgypDktXdb-HfZnSMK6A&v=5xniR1GN69U dosnt
this is my currunt code
how do i get it to just the v varibale from the url
Your querystring looks like "?v=5xniR1GN69U" the first time and "?feature=c4-overview&list=UUOYWgypDktXdb-HfZnSMK6A&v=5xniR1GN69U" the second time. You could have figured that out by yourself by simply debugging and checking your variables, since it doesn't even reach the code in the if block... Making a screenshot doesn't help people to figure out what's wrong with your code.
You might want to use Regex to parse the id Regex.Match(str, "v=(\w+)").Groups(1).Value
Just request the parameter v?
Request("v")
or
Request.Querystring("v")
EDIT
If in winforms. You can apply as suggested by #Markus
Try it like this
Dim querystring As String = url.Query
Dim myMatches As MatchCollection
Dim MyRegEx As New Regex("v=+(\w+)")
myMatches = MyRegEx.Matches(querystring)
For Each Row In myMatches
AxShockFlashMovie1.Movie = "https://www.youtube.com/v/" & Row.ToString() & ""
Next
You will also need to include
Imports System.Text.RegularExpressions
I've used HttpUtility.ParseQueryString in the past for something similar. Don't forget that youtube also offer tiny version of the urls with http://youtu.be/???

How do you convert a string into base64 in .net framework 4

So I've been going around the internet looking for a way to convert regular text(string) into base64 string and found many solutions. I'm trying to use:
Dim byt As Byte() = System.Text.Encoding.UTF8.GetBytes(TextBox1.Text)
TextBox2.Text = convert.ToBase64String(byt)
but it end up with an error saying
'ToBase64String' is not a member of 'System.Windows.Forms.Timer'.
What do I do to fix this? Or if there's a better way to code it please help.
Use System.Convert.ToBase64String(byt). Otherwise the timer is picked up as the innermost matching name.
Not the best name for a timer btw.