Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


C#
string s="firstname lastname city age country";


i need only for lastname.


input string s like this come:
1:
Bala kumar erode 28 india

2:
Pooja Palande pune 30 india

3:

Sasikumar raj mumbai 34 USA


I need for only last name output like this.

kumar

Palande

raj


Regards,
Karthikeyan,
Bangalore
Posted

1 solution

Hi,

First, split the string, and take the second string from the array:
C#
string s="firstname lastname city age country";
string[] parts = s.Split(' '); // split the string
string lastname = parts[1]; // take the second string from the array

Hope this helps.
 
Share this answer
 
Comments
Aarti Meswania 14-Dec-12 5:32am    
perfect!
my 5+ :)
Thomas Daniels 14-Dec-12 5:34am    
Thank you!
Aarti Meswania 14-Dec-12 5:36am    
welcome :)
pkarthionline 14-Dec-12 5:36am    
thanks.
Thomas Daniels 14-Dec-12 5:38am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900