【发布时间】:2015-04-28 09:28:58
【问题描述】:
我有一个包含全名条目的组合框,例如:John Smith、Mark Tall 等。
我写了以下内容:
string FullName = StudentSelectStudentComboBox.Text;
这会将“John Smith”作为字符串“FullName”。是否可以将“FullName”字符串分解为 2 个字符串?名字和姓氏?
【问题讨论】:
我有一个包含全名条目的组合框,例如:John Smith、Mark Tall 等。
我写了以下内容:
string FullName = StudentSelectStudentComboBox.Text;
这会将“John Smith”作为字符串“FullName”。是否可以将“FullName”字符串分解为 2 个字符串?名字和姓氏?
【问题讨论】:
你可以使用string.split
string str = "John Adams";
string[] names= str.Split(' '); //names[0]="John" names[1]="Adams"
【讨论】:
这个答案类似于the one above,但有一点不同: 如果你想变得花哨,你可以试试:
//////////////
//Names[0] = 名字,Name1 = 姓氏
string[] Names = StudentSelectStudentComboBox.Text.Split(' ');
////////
【讨论】: