Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!!!!
Posted

Try this
C#
// Suppose textbox = "First Last"
string s = textbox.Text ;
string[] name= s.Split(' ');
if(name.Length==2)
{
string firstname = name[0];
string lastname = name[1];
}
 
Share this answer
 
Comments
Member 9027483 26-Nov-12 2:34am    
it gives error like firstname is not exist in current context but i was done changes in select query also...plz help me..
Try the String.Split[^] method:
C#
string inp = "Mike Jones";
string[] parts = inp.Split(' ');
 
Share this answer
 
C#
String Name = "first last";
         String[] Spilted = Name.Split(new string []{" "}, StringSplitOptions.RemoveEmptyEntries);
         String firstName = Spilted[0];
         String lastName = Spilted[1];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900