分割字符串并将其分为两个字符串 [英] dividing string and assing it to two strings
本文介绍了分割字符串并将其分为两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将asp.net与c#一起使用.
我有一个下拉菜单.下拉菜单中的每个项目都有六个字符(AUDUSE,USDASD等).我希望当用户在下拉列表中选择任何项目时,将三个字符分配给一个字符串,将三个字符分配给其他字符串(字符串a = AUD,字符串b = USE等).
解决方案
string orig = "AUDUSE"; string a = orig.Substring(0, 3); string b = orig.Substring(3, 3);
string source = " 1234567890"; 字符串 a =源.Substring( 0 , 3 ); // 带有前3个字符 字符串 b = source.Substring( 3 ); // 取得前3个
< asp:DropDownList ID =" runat =" 服务器" AutoPostBack 真实"
span> =" DropDownList1_SelectedIndexChanged" < asp:ListItem > AUDUSE < /asp:ListItem >
< asp:ListItem > USDASD < /asp:ListItem >
< /asp:DropDownList >
代码:
受保护的 无效 DropDownList1_SelectedIndexChanged(对象发件人,EventArgs e)
{
字符串 a = DropDownList1.SelectedItem.Text.Substring( 0 , 3 );
int 长度=(DropDownList1.SelectedItem.Text.Length)- 3 ;
字符串 b = DropDownList1.SelectedItem.Text.Substring( 3 ,length);
}
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.
解决方案
string orig = "AUDUSE"; string a = orig.Substring(0, 3); string b = orig.Substring(3, 3);
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
Hi
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>AUDUSE</asp:ListItem> <asp:ListItem>USDASD </asp:ListItem> </asp:DropDownList>
code:
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); }
这篇关于分割字符串并将其分为两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文