C# string.split

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello good day friend today we will talk on she shot string dot split method so names cos can be see you have a string and you wanted to split the words out of those string based on some separator you can achieve this using string or split method like here is a string one two three four and one two three four suck concatenated by comma and he wanted to split this into separate items one two three four we can do this using string drops late method his another example like you have country names separated by space this is a stream and you wanted the countryand separately as string array you can achieve this using string dog split with that so let us see the usage like this is the split method which takes and care at it is the separator we can specify multiple separators and even specific options also you can specify them as a string also string at it and specify them string and is the number of substring you want so that can be specified and then this options so let us see string or split in action so here I mean an empty folder click open command from let me create a console application restore subsidy okay now let me when application Visual Studio code so yet here in Visual Studio code let go fix this perfect now we'll start it then string is true [Music] so the string can be okay no I wanted to [Music] and you see the separator I can specify discipline so let's specific space is a sobriety to start with you can specify options also so let's start with a very basic one to polish a concept okay now preserved now let us build this so this and let's see what comes out okay what's the result I'm counting like this because it's a string now we need to paint then you see we are getting separate element so this is at a stab that was a string now we are getting separate strings based on the separator we specified now we can specify the number of substance we want so if we specify a desk you can see we got do substring this end is a tested the taste and say say like this this destined so what I want to have two separate sentences out of it so we can do one thing you can separate it based on stop okay see this is at a step so now there is a space before we eat and I hope that this will be another space in front of it so what you can do we can know as we are putting character separator we cannot do it here so you can then do it using the strings is better so dot space let's run this so the issue has resolved now the thing is that though we can see not here actually there is no space of credit that is why it didn't work split out this one only for split up so if I put a space you will see that this dot has gone yeah so you see that is that if that that's what it is so now this is the one way another thing I wanted to show it to you like say if you take it like this now go and probably let's do it like this instead of this it's then separate it just to so you can put comma here and let's see what will come so this is a system as expected now what will happen if you boop say mistakenly that is one more comma somebody butit will happen you see there is empty strings coming in between now how can you take care of this so that will be taken care of by [Music] string speed options dot remove empty strings this option so I say this optional so let us see in this thing that has that in T space has gone that is how we can take care of this okay one more thing I wanted to show you that is it is giving this and then we have this one this okay so no we do here and this reading this Oh what will happen if I let us see what a table so you see the string is conveniences it's not throwing any exception but that strings come as is what will happen if we pass empty string so nothing is happening as usual no but if you pass this one as null and so I said yeah we are getting null references so that is about string dot space plate in action thank you for watching this
Info
Channel: Raj D
Views: 2,764
Rating: 4.8947368 out of 5
Keywords:
Id: hvUUM8QVlgA
Channel Id: undefined
Length: 7min 54sec (474 seconds)
Published: Fri Apr 24 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.