Click here to Skip to main content
15,921,169 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am using asp.net with c#.
i have a dropdown. each item in dropdown has six characters(AUDUSE,USDASD etc.). i want that when user select any item in the dropdown so three characters are assigned to one string and three to other(string a=AUD,string b=USE etc). how is it possible.
Posted

string orig = "AUDUSE";

string a = orig.Substring(0, 3);
string b = orig.Substring(3, 3);



http://msdn.microsoft.com/en-us/library/aka44szs.aspx
 
Share this answer
 
C#
string source = "1234567890";
string a = source.Substring(0,3); // take the first 3 characters
string b = source.Substring(3);   // take everything after the first 3
 
Share this answer
 
Hi

XML
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem>AUDUSE</asp:ListItem>
            <asp:ListItem>USDASD </asp:ListItem>
        </asp:DropDownList>



code:

C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       string a = DropDownList1.SelectedItem.Text.Substring(0,3);
       int length = (DropDownList1.SelectedItem.Text.Length) - 3;
       string b = DropDownList1.SelectedItem.Text.Substring(3,length);
   }
 
Share this answer
 
v2
Comments
Mohd Wasif 26-Jul-11 8:08am    
My 5
You can use String.Substring for that. Something like:
a = DropDownValue.Substring(0,3);
b = DropDownValue.Substring(2,3);

http://msdn.microsoft.com/en-us/library/aka44szs.aspx[^]

Good luck!
 
Share this answer
 
HI,
Findout the substirng


VB
yourstring.Substring(0,2)

VB
yourstring.Substring(3,5)

regards,
shefeek
 
Share this answer
 
v4

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