给定字符串的子字符串 [英] substring of given string
本文介绍了给定字符串的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi,
string s="firstname lastname city age country";
i只需要姓氏。
这样的输入字符串:
1:
Bala kumar erode 28 india
2:
Pooja Palande pune 30 india
3:
Sasikumar raj mumbai 34 USA
我只需要这样的姓氏输出。
kumar
Palande
raj
问候,
Karthikeyan,
班加罗尔
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
推荐答案
首先,拆分字符串,从数组中取出第二个字符串:
Hi,
First, split the string, and take the second string from the array:
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.
这篇关于给定字符串的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文