Click here to Skip to main content
15,887,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
hi
i have a PhoneCode and PhoneNumber are each text boxes
but in my database field record data is 044-12345678
how to SPLIT to TWO TEXT BOXSES (textbox1.text and textbox2.text)
pls help for me.

Thanks & Regards,
rpkaran:rose:
Posted
Comments
thatraja 19-Jan-11 9:41am    
Hi, keep always mention in your question or in Tag which language you are using, so you can get the correct answer. But our people already given the answer in C#. :-)

hi,
use string.split() function.
textbox1.text=mystring.split('-')[0];
textbox2.text=mystring.split('-')[1];



Hope this may help you.
 
Share this answer
 
v2
Comments
Hiren solanki 19-Jan-11 6:29am    
A good Answer.
Blesson Mathew 19-Jan-11 6:38am    
Thank You Hiren Solanki
Assuming you want to split the string on the hyphen, do this:

C#
string myString = "123-4567890";
string[] parts = myString.Split("-");


At that point, parts[0] contains "123", and parts[1] contains "4567890".
 
Share this answer
 
Comments
Hiren solanki 19-Jan-11 6:29am    
Good answer John.
C#
string input = "044-12345678";
 string pattern = "-";            // Split on hyphens

string[] substrings = Regex.Split(input, pattern);
 foreach (string  match in substrings)
 {
     Console.WriteLine("'{0}'", match);
  
 }



and then assign it to each textboxes.
 
Share this answer
 
v2
Comments
Hiren solanki 19-Jan-11 6:29am    
Why to go with such a long way if you can simply achieve it using String.Split() ?
sofia3 19-Jan-11 6:35am    
actually i hv just tried this method using regex

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