Splitting String into 2 parts based on seperator using C#

for example if i have a String “santosh-kumar”

so i just want to split them and Store into 2 strings variables like

String a = “santosh”

and

String b = “kumar”

so in order to do this the solution is

string strLeaf = "Santosh-Kumar";
string[] parts = strLeaf.Split(new char[] { "-" });
string a = null;
string b = null;

a = parts[0];
b = parts[1];
in this code iam using
strLeaf.Split(new char[] { "-" }) this statement to split string based on "-" this Charector
this approach is same as SUB STRING etc.,
Advertisements

About kakani santosh kumar

Working as Software Engineer in Prithvi Information Solutions having 3 years of Experience in Dotnet Framework ranging from 1.1 to 3.5
This entry was posted in Articles, Programming 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