Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to select the first 5 letters in textbox1 and the first 5 letters in textbox 2 and separate them with a - like: xxxxx-xxxxx into another textbox.

anyone have any suggestions?
Posted

If you can't even attempt this, you need to buy a beginners book and read it.

string s = textbox1.text.substring(0,5) + "-" + textbox2.text.substring(0,5)

Of course, this will blow up if there's less than 5 chars in the textbox, you need to add code to deal with that. and in general, for get ASP.NET, you're too much of a beginner to worry about that. Learn how to do basic code first.
 
Share this answer
 
this is what i ended up doing: thanks for the help though Christian. I ended up changing them to dropdownlists but it works the same for textboxes.

VB
Dim mystring As String = DropDownList3.SelectedItem.Text.ToString()
Dim substring As String = mystring.Substring(0, 5)

Dim mystring2 As String = DropDownList4.SelectedItem.Text.ToString()
Dim substring2 As String = mystring2.Substring(0, 4)

Dim mystring3 As String = TDropDownList.SelectedItem.Text.ToString()
Dim substring3 As String = mystring3.Substring(0, 3)

refnumber.Text = substring + "-" + substring2 + "-" + substring3
 
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