求助??? 急 对字符串的截取

sqqlovezqy 2009-04-28 10:38:02
最短租期:半年|付款要求:年付|押金要求:两月租金|入住时间:agew|看房时间:gaweg 截取:跟|之间的字符 c#

并将值赋给指定的文本框中
...全文
71 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ysw830 2009-04-28
  • 打赏
  • 举报
回复
string[] array = str.Split(new char[2]{':','|'});
for (int i = 0; i < array.Length; i++)
{
switch (array[i].ToString())
{
case "最短租期":
for (int j = 0; j <rblShortLease.Items.Count; j++)
{
if (rblShortLease.Items[j].Text == array[i + 1].ToString())
rblShortLease.Items[j].Selected = true;
}; break;
case "付款要求":
for (int j = 0; j < rblPay.Items.Count; j++)
{
if (rblPay.Items[j].Text == array[i + 1].ToString())
rblPay.Items[j].Selected = true;
}; break;
case "押金要求":
for (int j = 0; j < rblForegift.Items.Count; j++)
{
if (rblForegift.Items[j].Text == array[i + 1].ToString())
rblForegift.Items[j].Selected = true;
}; break;
case "入住时间": txtLiveDate.Text = array[i + 1].ToString(); break;
case "看房时间": txtLookDate.Text = array[i + 1].ToString(); break;
}
}
dxiuquan 2009-04-28
  • 打赏
  • 举报
回复
测试过的代码:

string _ValueText = "工期:半年|付款要求:年付|押金要求:两月租金|入住时间:agew|看房时间:gaweg ";
char[] sep ={ '|',':' };
string[] val = _ValueText.Split(sep);
for (int i = 0; i < val.Length; i++)
{
if (i % 2 == 1) MessageBox.Show(val[i]);
}
shenmixiaozi 2009-04-28
  • 打赏
  • 举报
回复
以上方法都不错!
sqqlovezqy 2009-04-28
  • 打赏
  • 举报
回复
能有具体的代码吗??
wonture 2009-04-28
  • 打赏
  • 举报
回复
string[] strs = "你的字符串".split('|');
love_幸运儿 2009-04-28
  • 打赏
  • 举报
回复
string str = "最短租期:半年|付款要求:年付|押金要求:两月租金|入住时间:agew|看房时间:gaweg";
string[] array = str.Split('|');
txt.Text=array[0].toString();
txt.Text=array[1].toString();
txt.Text=array[2].toString();
txt.Text=array[3].toString();
txt.Text=array[4].toString();
zgke 2009-04-28
  • 打赏
  • 举报
回复
string _ValueText = "半年|付款要求:年付|押金要求:两月租金|入住时间:agew|看房时间:gaweg ";

string[] _Value = _ValueText.Split(new char[]{':'},StringSplitOptions.RemoveEmptyEntries);

for (int i = 0; i != _Value.Length; i++)
{
string[] _Text = _Value[i].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
if (_Text.Length == 2)
{
MessageBox.Show(_Text[0], _Text[1]);
}
}
love_幸运儿 2009-04-28
  • 打赏
  • 举报
回复
string str = "最短租期:半年|付款要求:年付|押金要求:两月租金|入住时间:agew|看房时间:gaweg";
string[] array = str.Split('|');
txt.Text=array[0].toString();
txt.Text=array[1].toString();
txt.Text=array[2].toString();
txt.Text=array[3].toString();
txt.Text=array[4].toString();
dxiuquan 2009-04-28
  • 打赏
  • 举报
回复
提供个思路:用string的split方法,可以先split‘|’,然后split‘:’;也可以直接split‘|’和‘:’,然后取奇数下标的值。

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧