Click here to Skip to main content
Rate this: bad
good
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 at 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
0 Sergey Alexandrovich Kryukov 6,252
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
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