开发者

C# ComboBox Selected Text To Multiple Strings

I have a combobox that has the entries of a full na开发者_开发知识库me, eg: John Smith, Mark Tall, etc.

I have written the following:

string FullName = StudentSelectStudentComboBox.Text;

This gets "John Smith" as the string 'FullName'. Is it possible to break down 'FullName' string into 2 strings; FirstName and LastName?


You can just use string.split

string str = "John Adams";
string[] names=   str.Split(' ');    //names[0]="John"   names[1]="Adams"


This answer is similar to the one above but with a twist: If you want to get fancy you can try:

///////////////

//Names[0] = first name, Name1 = last name

string[] Names = StudentSelectStudentComboBox.Text.Split(' ');

////////

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜