how do i get a substring without predefined length

UserName = John Doe

I just want to retrieve only first name.
MeinhoonaaAsked:
Who is Participating?
 
p_davisConnect With a Mentor Commented:
string[] strArray = UserName .Split(" ");

string firstName = strArray[0];
0
 
p_davisCommented:
you can use the split method of the string class and split on the " " (space) and it returns a string array then you can just retrieve the 0 index of the array for the first name
0
 
MeinhoonaaAuthor Commented:
sample please
0
 
p_davisCommented:
^^

 =)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.