VB.NET Tutorial For Beginners - Strings & Basic String Manipulation (Visual Basic .NET)

  Рет қаралды 46,330

VB Toolbox

VB Toolbox

Күн бұрын

Пікірлер: 51
@devindwight4564
@devindwight4564 10 жыл бұрын
You make something so simple such as strings seem so fun to play with in VB!!
@VBToolbox
@VBToolbox 10 жыл бұрын
:-D And it should be fun! Programming is the ultimate "sandbox" game, whether you're using it for business or just as a hobby. You can make whatever you want of it and can do amazing things and improve efficiency as you learn to use different tools. You start out making castles with your hands, and then you realize that you could use a bucket to make awesome towers more efficiently. It's tons o' fun!
@devindwight4564
@devindwight4564 10 жыл бұрын
This inspires me to make an instructional VB form that I can use to reference and to pass along to other growing programmers :D
@brianbrewster6532
@brianbrewster6532 10 жыл бұрын
One of the best tutorials I ever watched! The narrator had a pleasant voice and seemed most knowledgeable on the subject matter. However; I was looking for single character search by nth placement in a string.
@VBToolbox
@VBToolbox 10 жыл бұрын
Thank you, Brian! :-) What you could do is loop through the string characters and capture each matching character index to a list or array. Then you'll have an index marker for each occurrence of the character that you're seeking.
@tshava
@tshava 6 жыл бұрын
The best toutorial ever..! Keep up the good work. This helped me in my project. Thank you
@RXY7
@RXY7 7 ай бұрын
Thank you so much. I hope you are doing very well.
@VBToolbox
@VBToolbox 7 ай бұрын
Thank you!
@james90902
@james90902 6 жыл бұрын
Just a thought - when working with larger strings, instead of looping, it's faster to use some maths to find a word / delimiter count. MsgBox(Len(txtOutput.Text) - Len(txtOutput.Text.Replace(" ", vbNullString)) + 1) It takes the length of the string, then subtracts the length of the string without the delimiter
@arjamal3867
@arjamal3867 8 жыл бұрын
Awesome tutorials!, I look for more useful tutorials, Thanks!!
@ranjanchhetry3945
@ranjanchhetry3945 4 жыл бұрын
You really helped me Sir. Thank you so much.
@amilcarjauregui1023
@amilcarjauregui1023 10 жыл бұрын
Thanks for all! your tutorials are awesome.
@spaxxvilejohn9095
@spaxxvilejohn9095 2 жыл бұрын
Hello. I was really hoping you'd show us how to access a certain string inside the main string using the split function. I understand how to split but how to access specific string inside the split string is the headache. Kindly anyone help
@VBToolbox
@VBToolbox 2 жыл бұрын
This will always require some degree of formatting consistency. If the string is formatted consistently and you know where the inner string begins and the length of the string you can capture with substring. Alternatively, you can use Regular Expressions, which has a bit of a learning curve, but is very powerful. You can use it to detect specifically formatted substrings (i.e., urls, email addresses, phone numbers, and much more).
@NewVidDotCo
@NewVidDotCo 9 жыл бұрын
Awesome tutorials! Thanks!!
@animenarra
@animenarra 3 жыл бұрын
hi, is there a way to copy only the word found in the output box? for example, the output is "hi hello how are you?" and i search for "hello" it will copy "hello" to my clipboard
@thiery572
@thiery572 5 жыл бұрын
Cool functions.
@baherwahby22
@baherwahby22 Жыл бұрын
Again great viedo , and please answer mij question how long it takes you to get this level is very important to me because i am freed to give up
@AardaerimusDAritonyss
@AardaerimusDAritonyss Жыл бұрын
Hello again, baherwahby22! :-) Don't give up! If it's something you really want to learn, you'll drive yourself to it. I remember a lot of that frustration, though. My main secrets are: 1.) Pick a simple challenge - especially a topic you find interesting, if possible - and focus on that until you figure it out - then make it better. Simply ask yourself the question "Can I do this?", then keep trying until you succeed, Even if you don't succeed, you'll learn so many thing along the way that become tools you can use on other projects. 2.) Repeat your work, over and over again. It's painful and frustrating - but don't be tempted to copy and paste old code to new projects - re do it. It's like kung fu and the secret to making it stick in your mind are the repetitions. 3.) As you progress, go back to your collection of old projects and note how much your skills and approach to problems have changed. Then, for fun, re-code them and see if you can make them faster, smaller, and much more efficient. I hope that helps! :-)
@sabarikrishna4900
@sabarikrishna4900 5 жыл бұрын
Sir, Can you please make a tutorial on "how to sort strings" for a list of students
@freestyle4961
@freestyle4961 7 жыл бұрын
Thanks for the video, how would I take chunks out of a piece of text? For example I have a string = "Hello my name is Johnathon and I like to say "Hey guys!" very loudly!" How would I take the Hey Guys! out of that string?
@Shivammishra-jx2qt
@Shivammishra-jx2qt 5 жыл бұрын
Thanks you sir
@UFOeurn
@UFOeurn 9 жыл бұрын
your video is awesome. i was wondering how would you take a string of characters and then concatenate each character to an output. example: if i entered "john" in a textfield, then how would i output it to "j-o-h-n".. so after each character there will be a dash.. hopefully that make sense.
@VBToolbox
@VBToolbox 9 жыл бұрын
Larry Oeurn Hey there, Larry. Sorry for the slow reply. What I would do is just loop through the characters and append the separator before each character after the first, like this: [In your TextBox1_TextChanged event] TextBox2.Clear() For i = 0 To TextBox1.Text.Count - 1 If Not i = 0 Then TextBox2.AppendText("-") TextBox2.AppendText(TextBox1.Text.Chars(i)) Next 1.) Clear the TextBox2 to show updates in real-time, as you type 2.) Loop through the characters in the string of TextBox1 3.) For each character, except the 1st, add a - to TextBox2 I hope that helps. ;-)
@UFOeurn
@UFOeurn 9 жыл бұрын
thank you!!!!
@VBToolbox
@VBToolbox 9 жыл бұрын
Larry Oeurn Sure thing, Larry. :-)
@1aonlinecomputerservices87
@1aonlinecomputerservices87 5 жыл бұрын
junk1 = arr(0) + "+" junk1 = junk1 + arr(1) + "+" junk1 = junk1 + arr(2) + "+" Thanks for the reply below. Let me see if I can explain better. In the above I get complaints for microsoft message: IDE0054 Use compound assignment in the error section where it tells you, that you have so many errors or so many warnings and so many messages. I've done one large program and all 3 are 0's when I compile. the program with the stuff above. Telling me I should be doing something like count = count + 1
@Intanputriifar
@Intanputriifar 8 жыл бұрын
Hey please help me. I was learn vb.net about String manipulation like this. example : Input = KZbin, output = You2tbe. or others Input = Visual Basic, Output = Visua2l Bsic. Please give me the code.. thanks
@jeffuday573
@jeffuday573 2 жыл бұрын
How do we get sigma sign in vb.net
@VBToolbox
@VBToolbox 2 жыл бұрын
ChrW(931) Example: MsbBox(ChrW(931))
@VBToolbox
@VBToolbox 2 жыл бұрын
ChrW(931) Example: MsbBox(ChrW(931))
@traceyrowsell6240
@traceyrowsell6240 8 жыл бұрын
Hi, how do you do a word count of only unique words, e.g. it only counts the word 'the' once in any sentence
@VBToolbox
@VBToolbox 8 жыл бұрын
You could make a function to split the string (sentence) by it's spaces, remove any blanks, force casing, and add the unique words to a list collection. Then you return the count of words added to the list. Example: ' create a wordlist in your main form class Private lstWords As New List(Of String) ' create a word counter function Private Function WordCount(MyString As String) As Integer Dim punct As String = "~#!@$%^&*()_-+=;," lstWords.Clear() ' remove punctuation For Each c As Char In MyString If punct.Contains(c) Then MyString = MyString.Replace(c, "") Next ' split on spaces, add to wordlist, and remove empty lines For Each word As String In Split(MyString, " ", -1) If Not String.IsNullOrWhiteSpace(word) AndAlso Not lstWords.Contains(LCase(word)) Then lstWords.Add(LCase(word)) End If Next Return lstWords.Count End Function Now you can try it out: Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim SomeString = "The lion, the witch, and the wardrobe - Wow!" MsgBox(WordCount(SomeString)) ' Optional: review words in wordlist 'For Each w In lstWords ' MsgBox(w) 'Next End Sub
@jay-arbautista1270
@jay-arbautista1270 8 жыл бұрын
hey please make a tutorial that the first letter will convert to uppercase please
@VBToolbox
@VBToolbox 8 жыл бұрын
+Jay-ar Bautista Try this function: Private Function CapFirst(Text As String) As String If String.IsNullOrEmpty(Text) Then Return Text Dim cArray() As Char = Text.ToCharArray cArray(0) = UCase(cArray(0)) Return New String(cArray) End Function You can then test it like this: Dim MyString As String = "hello vbtoolbox" MsgBox(CapFirst(MyString))
@MyZerocool007
@MyZerocool007 8 жыл бұрын
How do I replace strings in all say *.txt files in a user given path?
@VBToolbox
@VBToolbox 8 жыл бұрын
You can use the DirectoryInfo and FileSystemInfo objects in [Imports System.IO] to get a list of .txt files in a specified directory. Using their FileSystemInfo.FullName property, you can setup your StreamReader/StreamWriter to access each file and update them as desired. Example of listing files [adding to a ListBox control]: Private Sub GetFiles(Path As String) Dim DI As New DirectoryInfo(Path) ListBox1.Items.Clear() For Each fsi As FileSystemInfo In DI.GetFileSystemInfos If fsi.Extension = ".txt" Then ListBox1.Items.Add(fsi.FullName) Next End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load GetFiles("C:\tmp") End Sub
@MyZerocool007
@MyZerocool007 8 жыл бұрын
Actually I was looking to create a simple application where there is a text box in which I will give the path of the folder and a button in which I will code the replace operation, so when I press the button the replace will happen to all *.txt files in the path which I gave in the text box. How do I achieve that? Thanks in advance..:)
@VBToolbox
@VBToolbox 8 жыл бұрын
You can use the same method I provided before, but supply the "Path" parameter from the textbox. If you add a FolderBrowserDialog and a button [to browse], you can easily browse for a desired path and send it to the TextBox. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click If FBD.ShowDialog = Windows.Forms.DialogResult.OK Then TextBox1.Text = FBD.SelectedPath End If End Sub Then, when you hit your "Go" button to process the files, just run your replace method [like I did for the GetFiles() method above]. YourReplaceMethod(TextBox1.Text)
@chandrbatijatav7682
@chandrbatijatav7682 5 жыл бұрын
Cddh Dbcd😚🤡😉☺️ 😇🙂🤓😎😋😚 😁🏢🏗️🗻🏞️ 🇦🇪🇦🇹🇦🇨🇦🇪🇦🇫🇦🇬🇦🇮🇦🇱🇦🇲🇦🇶🇦🇴🇦🇸🇦🇷🇦🇹🇦🇺🇦🇼🇦🇿🇦🇽🇦🇿🇧🇦🇧🇧🇧🇩🇦🇸🇧🇪🇧🇫🇧🇬🇧🇭🇧🇯🇧🇮🇧🇲
@buddyroach
@buddyroach 10 жыл бұрын
how do you Find Next?
@VBToolbox
@VBToolbox 10 жыл бұрын
I'll PM you the code. :-)
@buddyroach
@buddyroach 10 жыл бұрын
thanks man!
@BhattaraiManish534
@BhattaraiManish534 9 жыл бұрын
thanks very much for your tutorial,i just need the help for transferring only the fixed strings or content from one text box to another for eg-i need to transfer only JOHN from the text NAME=JOHN can you help i would really appreciate
@VBToolbox
@VBToolbox 9 жыл бұрын
If the format remains consistent, you could use the "=" as a delimiter (string splitter). Example: MsgBox(Split("NAME=JOHN","=",-1)(1)) Alternatively, if you have many similar strings [e.g., FIRSTNAME=JOHN, LASTNAME=SMITH] you could create a reusable function: Private Function GetValue(Val As String) As String If Split(Val, "=", -1).Count > 1 Then Return Split(Val, "=", -1)(1) Return "" End Function Then you can push any similar values to any output you desire. TextBox2.Text = GetValue(TextBox1.Text) or TextBox2.Text = GetValue("FIRSTNAME=JOHN") TextBox3.Text = GetValue("LASTNAME=SMITH") I hope that helps. :-)
@BhattaraiManish534
@BhattaraiManish534 9 жыл бұрын
VB Toolbox can you explain this Private Function GetValue(Val As String) As String If Split(Val, "=", -1).Count > 1 Then Return Split(Val, "=", -1)(1) Return ""part my problem is i have a multiline textbox1 containing first-name="john" in one line and last-name="smith" in other line and i want to transfer only john in separate single line textbox2 and smith in next single line textbox3 couldn't figure out how to solve as its my project thanks for your help and giving time
@VBToolbox
@VBToolbox 9 жыл бұрын
manish bhattarai Hello. :-) Which part of the function would you like me to explain? In a nutshell, the Split() method breaks a string apart using a desired symbol and creates an array from those pieces. In my example, it breaks the string into pieces wherever it finds the "=" symbol. The .*Count* function returns the count of values stored in the array. Example: Splitting "first-name=john" at the = sign will produce an array with two values "first-name" and "john". Because "first-name" was the first value found, its index in the array is *0*, next is "john", so the index of "john" is *1*. If there were more = signs, the next split would be array index *2*. [Example: Split("name=john=smith","=",-1) would return an array like this: 0 - name 1 - john 2 - smith So, the .Count will return *3* values total. If you want to get a specific value from that array, you just need to use its index: Split("name=john=smith","=",-1)(0) will return *name* Split("name=john=smith","=",-1)(1) will return *john* Split("name=john=smith","=",-1)(2) will return *smith* In the GetValue() function above, I only wanted the value that came after name=, so I said: If Split(Val, "=", -1).Count > 1 Then Return Split(Val, "=", -1)(1) That should return "john" since john is at index position *1* . If all else fails, and nothing was found in array index 1 (e.g., .Count is less than 1) then Return "" ; Essentially, return a blank string on a failure to locate a value.
@nestorcosio7088
@nestorcosio7088 8 жыл бұрын
Creat video regards
VB.NET Tutorial For Beginners - Using Arrays (Visual Basic .NET)
39:32
А ВЫ ЛЮБИТЕ ШКОЛУ?? #shorts
00:20
Паша Осадчий
Рет қаралды 7 МЛН
No, Einstein Didn’t Solve the Biggest Problem in Physics
8:04
Sabine Hossenfelder
Рет қаралды 273 М.
VB.NET Tutorial - Dynamic Arrays (Visual Basic .NET)
16:28
VB Toolbox
Рет қаралды 16 М.