开发者

C# ComboBox Selected Text To Multiple Strings

开发者 https://www.devze.com 2022-12-10 17:21 出处:网络
I have a combobox that has the entries of a full na开发者_开发知识库me, eg: John Smith, Mark Tall, etc.

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

精彩评论

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