.NET interview questions: -Show practically how to parse values from string?

This is one of the most interesting topics asked by the interviewers to check how you can handle/solve this complicated situation in much easier ways. Most of the junior developers answer this question like they will run “For loop” and will check for “, (comma)” and later pass the value to the variables, this answer is also right but the interviewers will not be fully satisfied with this answer.

So the answer for the question should be by using “Split” function.

Split: – The split function of a string class allows you to extract
individual values separated by specific character.

Now, let’s do a small practical demonstration to see how exactly “Split” function help to parse the value from a string in much easier way.

Let’s create a new project on console application for that Go to >
New>File>Project>Windows> Select ConsoleApplication.

Now, just add the below code snippet in the main class.

staticvoid Main(string[] args)
{
string str = "Shiv,India,966457";// created a string variable and assigned values.
string[] values = newstring[2];// created array.
values = str.Split(',');// Used split function.
}

Note that, as soon as you use“Split” function in your code the VS business
Intellisence will display something like below diagram.

Now, just put small debug pointer on the below line.

Later, just run your application the debug pointer will stop at the line just press F10 once and the move  mouse pointer on the values you will find result like below diagram.


In above diagram you can clearly see that now the string values are easily parsed to the array variables by using “Split” function.

View more video on different types of collections in .NET as follows: –


Get our tutorials on important .NET interview questions

Regards,

Visit for author’s more blog on Most asked .NET interview questions

Advertisements

About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
This entry was posted in Uncategorized and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s