Click here to Skip to main content
12,401,832 members (62,081 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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 25-Nov-12 20:05pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try this
// Suppose textbox = "First Last"
string s = textbox.Text ;
string[] name= s.Split(' ');
if(name.Length==2)
{
string firstname = name[0];
string lastname = name[1];
}
  Permalink  
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..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try the String.Split[^] method:
string inp = "Mike Jones";
string[] parts = inp.Split(' ');
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

String Name = "first last";
         String[] Spilted = Name.Split(new string []{" "}, StringSplitOptions.RemoveEmptyEntries);
         String firstName = Spilted[0];
         String lastName = Spilted[1];
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100