将字符串分成两个变量 [英] split string into two variable
本文介绍了将字符串分成两个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据名字和姓氏搜索任何人..
我有一个文本框,其中我使用空格输入了名字和姓氏..
但是我想用数据库字段来匹配这两个名称.
在数据库中,名字和姓氏也有两个不同的字段..
所以如何将文本框输入的名称拆分为两个变量????
请帮我!!!!
i want to search any person according to first name and last name..
i have one text box in that i put first name and last name using space..
but i want to match that two name with database field..
in database also two different field for first name and last name..
so how can i split that textbox entered name into two variable?????
plz help me!!!!
推荐答案
尝试一下
// Suppose textbox = "First Last"
string s = textbox.Text ;
string[] name= s.Split(' ');
if(name.Length==2)
{
string firstname = name[0];
string lastname = name[1];
}
尝试使用字符串.拆分 [^ ]方法:
Try the String.Split[^] method:
string inp = "Mike Jones";
string[] parts = inp.Split(' ');
String Name = "first last";
String[] Spilted = Name.Split(new string []{" "}, StringSplitOptions.RemoveEmptyEntries);
String firstName = Spilted[0];
String lastName = Spilted[1];
这篇关于将字符串分成两个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文